[Qt-interest] QTcpSocket timeouts

Anatoly Burakov burakov.anatoly at googlemail.com
Thu Mar 18 03:12:28 CET 2010


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5238 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100318/adaf9764/attachment.bin 


More information about the Qt-interest-old mailing list