Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

High CPU consumption with QTcpsocket in QThread



  • I have desktop application written with Qt that I build on Windows . I’ve just now noticed that when connect a server with QTcpScocket, CPU consumption is quite high (around % 25 CPU when the QTcpSocket connect server in the thread), i create a class to manager a QTcpSocket and move the class to a separate QThread using moveToThread .in this thread ,i read or write data to server.the cpu always high even i does not communicate with the server.But if i close the QTcpSocket thread ,the cpu consumption became very low. Is there anything I might be able to do to improve on this?
    i use qt 5.2.1,in vs2008. i test qt5.3.1 ,the problem also exist.


  • Moderators

    Please share your threading code (if possible)? You need to be very careful when moving QObjects to a different thread:

    • the object cannot have a parent
    • subobjects need to be parented to the main object (the one being moved), or they need to be created after you moveToThread
    • it's best to use Qt::QueuedConnection when connecting slots and signals between threads. Connect statement should be invoked after moveToThread

Log in to reply