Search code examples
c++qt4qthreadqtcpserver

Qt - A simple echo server


How in Qt would you keep a thread alive in the QThreadPool; as far as I've seen there is only an option to run a QRunnable and I've been told they can't control the thread they are within. How would I, using the thread pool keep a socket alive and ready to read and write?


Solution

  • QThreadPool manages its own threads. QT Doc says that

    QThreadPool manages and recyles individual QThread objects to help reduce thread creation costs in programs that use threads.

    So you should not try to keep a thread alive. That breaks the purpose of thread pool.

    Also QT sockets are designed to work well with the main event loop. Why don't you try using them ?