Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QThread + QTcpSocket

QThread + QTcpSocket

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    issam
    wrote on last edited by
    #1

    Hi everybody !
    I have developed a Ping Pong game (table tennis) which can be downloaded from http://www.iissam.com/sources/codes.php (Qppong)
    I want to transform it to a network game by adding the capabilities to connect two players over a local network or using a network cable.
    Obvious, the game becomes a client(player2)/server (player1) application and the code contains two parts : client side and server side.
    In each part, a thread will run. The run() function of the thread contains a loop (while), which while the player does not leave the game will send or receive a stream of data (positions of the ball and the two rackets).
    The problem is that, when I execute the game, I get an infinite loop.
    has someone a solution ?

    http://www.iissam.com/

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SaiyanRiku
      wrote on last edited by
      #2

      I didn't saw your code but i think you should use the QThread::exec function instead a while loop, which give you an event loop for your thread, then connect your QTcpSocket to a disconnected signal to know when your player is gone.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RavensAngel
        wrote on last edited by
        #3

        Can we find the new code somewhere? It's hard to tell what is going on without this piece of information. What do you mean an infinite loop? You are in a while loop, should it break somewhere? What do you expect to do? Using a while loop in the run breaks the eventloop of the thread. So you won't process any events... as SaiyanRiku told, use the exec() method, to start the eventloop and process the messages coming from the tcpclient/server!

        1 Reply Last reply
        0
        • I Offline
          I Offline
          issam
          wrote on last edited by
          #4

          ok Thanks !
          I used QMainWindow::QTimerEvent instead of QThread ....

          http://www.iissam.com/

          1 Reply Last reply
          0
          • I Offline
            I Offline
            issam
            wrote on last edited by
            #5

            The new code is here http://www.iissam.com/sources/codes.php (3. Qppong) :)

            http://www.iissam.com/

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved