Hi everyone,
Let me explain my problem through an example. I have 2 different classes both running in different threads.
A.h (header file)
Class A
{
public:
A();
signals:
void sigA();
private slots:
void slotA();
}
A.cpp (source file)
A::A()
{
emit sigA();
}
void A::slotA()
{
//some processing
}
B.h
Class B
{
signals:
void sigB();
private slots:
void slotB();
}
B.cpp
void B::slotB()
{
emit sigB();
}
main.cpp
void main()
{
A objA;
B objB;
QObject::connect(&objA,
SIGNAL(sigA
()),
&objB,
SLOT(slotB
()), Qt
::BlockingQueuedConnection);
QObject::connect(&objB,
SIGNAL(sigB
()),
&objA,
SLOT(slotA
()), Qt
::BlockingQueuedConnection);
}
A.h (header file)
Class A
{
public:
A();
signals:
void sigA();
private slots:
void slotA();
}
A.cpp (source file)
A::A()
{
emit sigA();
}
void A::slotA()
{
//some processing
}
B.h
Class B
{
signals:
void sigB();
private slots:
void slotB();
}
B.cpp
void B::slotB()
{
emit sigB();
}
main.cpp
void main()
{
A objA;
B objB;
QObject::connect(&objA, SIGNAL(sigA()), &objB, SLOT(slotB()), Qt::BlockingQueuedConnection);
QObject::connect(&objB, SIGNAL(sigB()), &objA, SLOT(slotA()), Qt::BlockingQueuedConnection);
}
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 :-
emit sigB();
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
Bookmarks