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
A QThread should be used much like a regular thread instance: prepare an object (QObject) class with all your desired functionality in it. Then create a new QThread instance, push the QObject onto it using moveToThread(QThread*) of the QObject instance and call start() on the QThread instance. That's all.
A QThread object manages one thread of control within the program. QThreads begin executing in run(). By default, run() starts the event loop by calling exec() and runs a Qt event loop inside the thread. You can use worker objects by moving them to the thread using QObject::moveToThread().
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With