[Solved]Can't receive signal from another thread
Can't receive signal from another thread as following.
Using connect type as Qt::BlockingQueuedConnection, the thread blocks. But signal not received.
int main(int argc, char *argv)
QCoreApplication a(argc, argv);
class Thread1 : public QThread
void run( void )
qDebug() << "thread 1 started";
int i = 0;
msleep( 10 );
qDebug() << "i is: " + QString::number(i);
qDebug() << "Got I";
MyClass::MyClass(QObject *parent) :
thread1 = new Thread1();
connect(thread1, SIGNAL(MyThread1Signal()), this, SLOT(myClassSlot1()), Qt::BlockingQueuedConnection);
class MyClass : public QObject
explicit MyClass(QObject *parent = 0);
#endif // MYCLASS_H
[edit: please add @ code tags. Did it for you, Eddy]
Things I will try:
- move the connect from the constructor to the startAll method, between the start and wait of the thread
- change the exit with a simple return
- leave the connection in automatic mode (remove blocked queue).
But I'm totally not sure about any of them.
Change exit to return works. (Or remove wait() after start())
For these prevent thread from sleep or terminate.