Hi everyone,
Let me explain my problem through an example. I have 2 different classes both running in different threads.
Qt Code:
  1. A.h (header file)
  2. Class A
  3. {
  4. public:
  5. A();
  6. signals:
  7. void sigA();
  8. private slots:
  9. void slotA();
  10. }
  11.  
  12. A.cpp (source file)
  13. A::A()
  14. {
  15. emit sigA();
  16. }
  17. void A::slotA()
  18. {
  19. //some processing
  20. }
  21.  
  22. B.h
  23. Class B
  24. {
  25. signals:
  26. void sigB();
  27. private slots:
  28. void slotB();
  29. }
  30.  
  31. B.cpp
  32. void B::slotB()
  33. {
  34. emit sigB();
  35. }
  36.  
  37. main.cpp
  38. void main()
  39. {
  40. A objA;
  41. B objB;
  42. QObject::connect(&objA, SIGNAL(sigA()), &objB, SLOT(slotB()), Qt::BlockingQueuedConnection);
  43. QObject::connect(&objB, SIGNAL(sigB()), &objA, SLOT(slotA()), Qt::BlockingQueuedConnection);
  44. }
To copy to clipboard, switch view to plain text mode 

In short I am emitting sigA which is connected with slotB. From slotB I am emitting sigB which is connected with slotA. And both the connections are in BlockingQueuedConnection mode. As a result the application is going into deadlock when the following step is executed :-
Qt Code:
  1. emit sigB();
To copy to clipboard, switch view to plain text mode 
.
If I remove Qt::BlockingQueuedConnection from the connection between sigB and slotA then it's fine. But I want both to be in BlockingQueuedConnection i.e I want sigA to hang/wait until slotA hasn't finished executing. Can anyone explain me why deadlock is happening and how to achieve the same without causing deadlock?


-With regards,
sattu