I have a simple client-server program written in Qt, where processes communicate using MPI. The basic design I'm trying to implement is the following:
The first process (the "server") launches a GUI (derived from
QMainWindow
), which listens for messages from the clients (using repeat fireQTimer
s and asynchronous MPI receive calls), updates the GUI depending on what messages it receives, and sends a reply to every message.Every other process (the "clients") runs in an infinite loop, and all they are intended to do is send a message to the server process, receive the reply, go to sleep for a while, then wake up and repeat. Every process instantiates a single object derived from
QThread
, and calls itsstart()
method. Therun()
method of these classes all look like this:
from foo.cpp:
void Foo::run()
{
while (true)
{
// Send message to the first process
// Wait for a reply
// Do uninteresting stuff with the reply
sleep(3); // also tried QThread::sleep(3)
}
}
In the client's code, there is no call to exec()
anywhere, so no event loop should start.
The problem is that the clients never wake up from sleeping (if I surround the sleep()
call with two writes to a log file, only the first one is executed, control never reaches the second). Is this because I didn't start the event loop? And if so, what is the simplest way to achieve the desired functionality?