Although I have a fair amount of understanding of QObject, QThread and how to multi thread in Qt, I am having trouble understanding some of the scenarios.
Consider a class Myclass : QObject which is moved to another QThread.
class MyClass : QObject
{
public slots:
void slot1();
bool slot2();
void slot3();
}
I have a class
class Window
{
signals:
void sig1();
bool sig2();
private:
MyClass *myObj;
public:
void func()
{
connect(this, SIGNAL(sig1()), myObj, SLOT(slot1()), Qt::DirectConnection);
emit sig1();
qDebug("SIGNAL1 emitted!");
connect(this, SIGNAL(sig2(bool)), myObj, SLOT(slot2(bool)));
bool result = emit sig2();
myObj->slot3();
}
}
When
sig1is emitted I understand that theqDebug()will be executed only afterslot1()is executed. But isslot1executed inWindow threadorMyClass thread?In case of
sig2is it guaranteed thatresultwill store value returned byslot2or is it necessary for this connection to be direct?Is it correct to run
slot3as shown?slot3modifies class variables ofmyObjas well as it emits aSIGNALwhich is connected to aSLOTof the callingWindow object. If it is correct then when will the slot ofWindowbe executed and in which thread?