[Qt-interest] QTcpSocket timeouts

Bob Hood bhood2 at comcast.net
Thu Mar 18 03:37:11 CET 2010


You probably need to let the event loop run so that data from the
incoming connection can be processed and queued up for you.  That's
essentially what is happening when you post the dialog box (i.e., and
event loop runs and data is processed).


Anatoly Burakov wrote:
> Hi all
>
> I have a problem that is bugging me. I have two apps communicating via
> QTcpSockets. They both have QDataStreams on the sockets and have similar
> communication code. Generally this process looks like this:
>
> =================================================
> // Send a signal to other app
>
> stream << SomeSignal;	// integer
>
> // Wait for signal to be sent
> while (stream.device()->bytesToWrite() > 0) {
> 	if (!stream.device()->waitForBytesWritten(30000)) {
> 		// display error message
> 		QMessageBox::information(0, "", stream.device()->errorString());
> 		return;
> 	}
> }
>
> // Wait for an incoming signal
> while (stream.device()->bytesAvailable() < (int) sizeof(int))
> {
> 	if (!stream.device()->waitForReadyRead(30000)) {
> 	QMessageBox::information(0, "", stream.device()->errorString());
> 	return;
> 	}
> }
>
> // Read the incoming data
>
> stream >> reply;	// another integer
> ==================================================
>
> The problem is that for some reason the incoming signal process times
> out when using the above piece of code. However, it works perfectly fine
> when i put a QMessageBox between the two blocks (after sending and
> before recieving the signal). Am i missing something fundmental here?
>
> Best regards,
> Anatoly




More information about the Qt-interest-old mailing list