I have a class like this
class GUI : public QWidget, public QThread
When I do the above i get errors about connect signals. The error says "Reference to "connect" is ambiguous". Is there a way to inherit from both?
Thank you
I have a class like this
class GUI : public QWidget, public QThread
When I do the above i get errors about connect signals. The error says "Reference to "connect" is ambiguous". Is there a way to inherit from both?
Thank you
You can't. Both QWidget
and QThread
inherit (non-virtually) from QObject
. You therefore do not have virtual derivation, thus two copies of QObject
, which confuses the compiler. QObject
was specifically designed this way. See:
There are some who allegedly went around this (can't find the link right now, but it's out there on Google, I had the same trouble two weeks ago), but it is unsafe at best.
Edit: the best way would probably be to have another object inherit from QThread and keep that object as a member in your GUI
class. That is the sort of workaround most people do in this matter.
You cannot inherit from multiple QObjects.
You can inherit from one and make the other a member variable and work from there.
class GUI : public QWidget
{
QThread myThread;
};
You've named your class GUI - is this the main GUI of your program? See the examples in the Qt examples folder - they have sample programs on both GUI's and Threads.