PDA

View Full Version : Change GUI from server thread



zuperman
23rd January 2011, 15:45
Hello!
I'm trying to make a chess game that has a Qt GUI.
The game is played by two clients that communicate with a server. The server has implemented all the rules of the game and it only send the coordinates move to client or the error message. This messages are taken by the client in a thread, and the GUI is in another thread. How can I communicate the messages from one thread to another in order to make the moves I get from the server in the GUI or to show the error messages.
I can't put them both in the same thread because the first blocks the other.
I've tried with signals but it didn't worked, and I've tried to pass the Widget pointer into the second thread but still nothing.

Thanks for any suggestion!

tbscope
23rd January 2011, 17:41
This messages are taken by the client in a thread, and the GUI is in another thread.
Can you explain why you want to do this?


How can I communicate the messages from one thread to another ...
Signals and slots


I can't put them both in the same thread because the first blocks the other.
Then you do something wrong, like using blocking functions.


I've tried with signals but it didn't worked
What didn't work and how did you try this?


and I've tried to pass the Widget pointer into the second thread
That is not allowed in Qt.

Here's a nice example:
http://www.kdedevelopers.org/node/4377

squidge
23rd January 2011, 19:09
This messages are taken by the client in a thread, and the GUI is in another thread.For a simple client/server based system, I don't see why the client functions need to be in a seperate thread. They are asynchronous (non-blocking) so they can quite happily live in the GUI thread. All you are doing is increasing the complexity of your project for no gain.