Question

Thread with an event loop

We have created a QTcpServer object in a separate thread and it is listening for incoming connections and processing them as they occur. At some point the is deleted and there is nothing to generate events in the thread.

Does the thread go into an endless block (using memory but no cpu) if not manually deleted?

Thread without an event loop

A QTcpServer object created and is listening.

Is the QTcpServer.listen() preventing the thread to just run through all the code and naturally finish?

What about the incoming connections? Do they have to be manually polled for?

Was it helpful?

Solution

it is good practice to connect the finished signal of a thread to its own deleteLater slot so it can clean itself up, but this may cause dangling pointers if you keep a pointer to the QThread

QTcpServer.listen() will return immediately it just activates the port

when listening a TCPServer will emit a newConnection() signal each time a new connection is initiated by a client after which you can retrieve it with nextPendingConnection

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top