QThread + QTcpSocket
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 ?
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.
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!
ok Thanks !
I used QMainWindow::QTimerEvent instead of QThread ....
The new code is here http://www.iissam.com/sources/codes.php (3. Qppong) :)