Well, I'm not sure if i really know what you mean. But it looks like you want the thread to send a message through the socket and have it block until it receives a reply from the network client (or gui?).
First of all, why do you have to use a thread for this? It is not doing anything useful except sleeping and sending a message once it gets a reply. You could do it easily using the normal signal/slots with a non-threaded class. In case you didnt provide the full info and it does do something instead of waiting there are 2 solutions:
1. just give your thread an event-loop with the exec() function in your run method and connect the readyRead() signal of the socket to a slot in your thread. This is the non-blocking way.
2. in your run() method do something like:
forever {
socket->write(message);
socket->waitForBytesWritten();
socket->waitForReadyRead();
read_reply();
}
forever {
socket->write(message);
socket->waitForBytesWritten();
socket->waitForReadyRead();
read_reply();
}
To copy to clipboard, switch view to plain text mode
Can you maybe further explain why you need this thread or what it really does? Because i really think you dont need a thread for your task. Threads are a pain anyway, so evade them whenever possible! Just my 2 cents ;-)
Bookmarks