November 8, 2011

kevinm kevinm
Lab Rat
1 posts

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.

  1. 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

November 8, 2011

Gerolf Gerolf
Area 51 Engineer
3210 posts

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. [developer.qt.nokia.com]

 Signature 

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

 
  ‹‹ [Solved] Starting a GUI program through Terminal with Arguments      How to get the correct size from QStaticText ››

You must log in to post a reply. Not a member yet? Register here!