Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How to make the slot runs in receive thread?

    General and Desktop
    2
    2
    1475
    Loading More Posts
    • 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.
    • K
      kevinm last edited by

      Hi all,

      I have many TCPSocketThread to connect with users, and DataHandlerThread to deal with the data received from TCPSocketThread.
      There might be a lot of TCP connections, and each data transfer will affect database. So I implemented a Database ThreadPool to manage DataHandlerThreads.

      Look at this connect.
      @
      QObject::connect(pThread, SIGNAL(execFinished(TWorkThread*)), this, SLOT(dataDealFinishedEvent(TWorkThread*)));
      @
      pThread is DataHandlerThread. When this thread finished it's work, it should tell the socketThread it finished(execFinished), then this TCPSocketThread should return the DataHandlerThread to ThreadPool.

      As now, I can make the readyRead->dataReceivedEvent() work well, the TCPSocketThread::dataReceivedEvent now works in TCPSocketThread.

      In TCPSocketThread::dataReceivedEvent, I make that connect, anyway I debug, the triggerred thread are main thread or DataHandlerThread.(With Qt::DirectConnection, Qt::QueriedConnection)

      Are there any who can tell me how I can make the slot dataDealFinishedEvent runs in TCPSocketThread??

      Many thanks,
      Kevin

      Edit: code sections need to be wrapped in @ tags; Andre

      1 Reply Last reply Reply Quote 0
      • G
        giesbert last edited by

        is TCPSocketThread a subclas of QThread? If yes, the object itself belongs to the creating thread (typically the main thread), and the slot will be executed there. "Have a look at peppes article about threads.":http://developer.qt.nokia.com/wiki/ThreadsEventsQObjects

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply Reply Quote 0
        • First post
          Last post