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
sig1
is emitted I understand that theqDebug()
will be executed only afterslot1()
is executed. But isslot1
executed inWindow thread
orMyClass thread
?In case of
sig2
is it guaranteed thatresult
will store value returned byslot2
or is it necessary for this connection to be direct?Is it correct to run
slot3
as shown?slot3
modifies class variables ofmyObj
as well as it emits aSIGNAL
which is connected to aSLOT
of the callingWindow object
. If it is correct then when will the slot ofWindow
be executed and in which thread?