Emadpres
Emadpres

Reputation: 3737

Multiple inheritance with QThread and QWidget ( Multiple inheritance with QObject )

I'm going to design OgreWidget class -A portable renderer widget with Qt.

(With my design), I think my class need to be inherited with QThread (for infinite render loop ) and QWidget ( target widget for ogre to render there) .

But according to many documentation and articles (for instance this), Virtual inheritance with QObject is not supported . Result of this inheritance will be such a error:

QObject is an ambiguous base of OgreWidget

How should I resolve this problem ?

PS: In my old design , I create a separate QWidget , and Send It's WId to my OgreWidget as target widget. However, I'm now going to design a better and cleaner interface.

Upvotes: 0

Views: 2009

Answers (2)

friendzis
friendzis

Reputation: 809

That's impossible, because both QThread and QWidget in the end resolve to QObject base class

This thread answers your question: how can i inherit from both QWidget and QThread?

Upvotes: 2

John
John

Reputation: 236

The QThread documentation is misleading, you don't need to and shouldn't be sub classing QThread here for your widget.

"You're doing it wrong" - http://labs.qt.nokia.com/2010/06/17/youre-doing-it-wrong/

You should either:

  • Create a QThread ogreThread, create your ogreWidget and ogreWidget.moveToThread(&ogreThread), or
  • Create a QThread wrapper that allows you to tell it to create a new object of type T directly in the new thread.

Upvotes: 0

Related Questions