Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. High CPU consumption with QTcpsocket in QThread
Qt 6.11 is out! See what's new in the release blog

High CPU consumption with QTcpsocket in QThread

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wearilybird
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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

      (Z(:^

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved