How to make the slot runs in receive thread?

  • 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,

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

  • 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.":

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.