Pong

June 25th 2014, QTcpSockets, QThreads and the Event Loop in Qt

June 24th 2014 SSL Security | | June 25th 2014 QTcpSocket State

TCP Sockets in Qt are basically a state machine that reacts on asynchronous events. So for QTcpSocket to work one needs to have an event loop running.

But what if one does not have a GUI with an event loop? Then the solution is to put everything into a QThread. Every QThread has an event loop. The thread will dispatch incoming data packets, even if the event loop is not explicitly “exec()”ed in the thread’s run() method and even if the synchronous socket methods such as waitForReadyRead() are used. On the other hand, if there is no event loop, then waitForReadyRead() will block forever.

June 24th 2014 SSL Security | | June 25th 2014 QTcpSocket State

Options: