I'm developing a project that connects through SSH to download some config files, parse them and allow the user to modify them. For the SSH connection I'm using libssh in a worker thread. During the stablishment of the connection (which takes place in the worker thread) sometimes I need to ask the user if he wants to accept the host key. So I wanted to emit a signal from the worker thread and connect it to the GUI thread so that it calls QMessageBox::question() and returns the value (a boolean) to the worker thread, which is meanwhile waiting for the reply of the GUI thread. But I have some problems. The first one is with signal/slots you can't return a value. Ok, I can pass a pointer to the variable and modify it from the GUI thread and since the worker thread is waiting for the GUI thread, I don't need to use a mutex. But the problem is when I emit the signal, the worker thread continues the execution instead of waiting for the reply as if it was a normal function call (but across threads). I could make the worker thread sleep and wake it up from the GUI thread after we get the answer from the user, but I don't think that's a good idea because if the signal was not connected to any slot the worker thread would sleep forever and I would like to keep my code as clean as possible, having a default value for the boolean and trying to modify it if there's something connected to the signal, otherwise taking the default value. Any idea on how to implement this?
Bookmarks