Re: QThread and QTcpSocket
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:
Code:
forever {
socket->write(message);
socket->waitForBytesWritten();
socket->waitForReadyRead();
read_reply();
}
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 ;-)
Re: QThread and QTcpSocket
Hi,
Thanks for reply but I had solved yet.
Quote:
First of all, why do you have to use a thread for this?
Because there are other Threads that are creting messages and them send the message to the communication thread that have to send it.
But don't worry about it, as I said, I solved it.
Thanks,