Results 1 to 3 of 3

Thread: Change GUI from server thread

  1. #1
    Join Date
    Jan 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Lightbulb Change GUI from server thread

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Change GUI from server thread

    Quote Originally Posted by zuperman View Post
    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

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change GUI from server thread

    Quote Originally Posted by zuperman View Post
    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.

Similar Threads

  1. Memory raising forever in server thread application
    By ruben.rodrigues in forum Newbie
    Replies: 4
    Last Post: 1st July 2010, 21:54
  2. Replies: 1
    Last Post: 23rd April 2010, 13:23
  3. Replies: 10
    Last Post: 22nd July 2009, 23:52
  4. how to change 'Thread title' in the forum
    By rishiraj in forum General Discussion
    Replies: 1
    Last Post: 1st April 2009, 07:00

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.