Can't receive signal from another thread as following.
Using connect type as Qt::BlockingQueuedConnection, the thread blocks. But signal not received.

main.cpp
Qt Code:
  1. #include "myclass.h"
  2.  
  3.  
  4.  
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. QCoreApplication a(argc, argv);
  9.  
  10.  
  11. MyClass myClass;
  12. myClass.startAll();
  13.  
  14. return a.exec();
  15. }
To copy to clipboard, switch view to plain text mode 

thread.h
Qt Code:
  1. #include <QtCore/QCoreApplication>
  2. #include <QThread>
  3.  
  4. #include <QDebug>
  5.  
  6.  
  7.  
  8. class Thread1 : public QThread
  9. {
  10. Q_OBJECT
  11. public:
  12. void run( void )
  13. {
  14. qDebug() << "thread 1 started";
  15. int i = 0;
  16. while(1)
  17. {
  18. msleep( 10 );
  19. i++;
  20. qDebug() << "i is: " + QString::number(i);
  21. if(i==1000)
  22. {
  23. qDebug() << "Got I";
  24. emit MyThread1Signal();
  25. exit();
  26. }
  27. }
  28. }
  29. signals:
  30. void MyThread1Signal();
  31. };
To copy to clipboard, switch view to plain text mode 




myclass.cpp
Qt Code:
  1. MyClass::MyClass(QObject *parent) :
  2. QObject(parent)
  3. {
  4. thread1 = new Thread1();
  5. connect(thread1, SIGNAL(MyThread1Signal()), this, SLOT(myClassSlot1()), Qt::BlockingQueuedConnection);
  6. }
  7.  
  8.  
  9. void MyClass::startAll()
  10. {
  11. thread1->start();
  12. thread1->wait();
  13. }
  14.  
  15.  
  16. void MyClass::myClassSlot1()
  17. {
  18. qDebug()<<"Signal received";
  19. }
To copy to clipboard, switch view to plain text mode 

myclass.h
Qt Code:
  1. #ifndef MYCLASS_H
  2. #define MYCLASS_H
  3.  
  4. #include <QObject>
  5.  
  6. #include "threads.h"
  7.  
  8. class MyClass : public QObject
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit MyClass(QObject *parent = 0);
  13.  
  14. void startAll();
  15.  
  16. signals:
  17.  
  18. public slots:
  19. void myClassSlot1();
  20.  
  21. private:
  22. Thread1* thread1;
  23. };
  24.  
  25. #endif // MYCLASS_H
To copy to clipboard, switch view to plain text mode