PDA

View Full Version : C++ - QDbus in multithread system



Mistrale
12th November 2016, 23:09
Hi everyone,

I cannot push my code but i'll try to explain it the easier I can.

I have two objects of the same class (Block) thats inherit from Q_Object with a slot function (catchSignal(QString)), a signal emitted (finished()), and a main function (execute())

This is the main call for :

void Block::execute() {
- allocate new QNetworkAccessManager, do a request and connect the finished(QNetworkReply *) signal to a QEventLoop's quit() function
- connect QDBusConnection::sessionBus()'s particular signal (emit from a another program) to the catchSignal(Qstring) slot
- connect the Block emitted signal (finished()) to another QEventLoop's slot (quit())
- disconnect QDBusConnection::sessionBus() from the signal I wanted to listen to
}

void Block::catchSignal(QString str) {
- must be called 6 times by each object
- when its has been called 6 times ---> emit finished() signal
}

I run the execute function of my two objects in a separate thread (c++ thread) but I noticed that when the main thread finished before the other, I dont received all event in my object from 2nd thread, and this last blocks for infinity.

I tried to see whats happening on DBUS with dbus-monitor under linux, all signal required are well send.

Do u have any ideas ?

If u need more detail about the program u can ask question

Mistrale
13th November 2016, 02:51
After trying to mocking my block thread ID == 0 its seems that DBUS sessions has having trouble in my thread id 1

anda_skoa
13th November 2016, 12:44
Your description doesn't really say which thread your objects live in.

Are they created by the main thread? Have they be moved into the secondary thread?
Is the secondary thread running an event loop?
Is the D-Bus connection handled by the main thread?

You should really post at least some code.

Cheers,
_