1

I compiled a program for Qt5, and now it has different run-time behavior.

In Qt5, the socket is not disconnected until the event loop is reentered, even though I explicitly wait for that with waitForDisconnected().

For example this code:

socket.disconnectFromServer();
qDebug("Started waitForDisconnected...");
socket.waitForDisconnected();
qDebug("Finished waitForDisconnected.");
qDebug("Started Sleep for 10 seconds...");
Sleep(10*1000);
qDebug("Finished Sleep.");
qDebug("Started QEventLoop...");
QEventLoop().exec();
qDebug("Finished QEventLoop.");

Will give the following output:

Started waitForDisconnected...
QLocalSocket::waitForDisconnected() is not allowed in UnconnectedState
Finished waitForDisconnected.
Started Sleep for 10 seconds...
Finished Sleep.
Started QEventLoop...

But the socket itself is not deleted until after I get the Started QEventLoop... message - I know that because I monitor this from another application that waits for the socket to disconnect from the other side.

When compiled with Qt4, the same code works as it should, the socket is disconnected before waitForDisconnected() has returned. On Qt5 waitForDisconnected() returns claiming that the socket has been disconnected, when in fact it has not.

My version of Qt is 5.1.1.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • actually waitForDisconnected is signaling an error as shown in `QLocalSocket::waitForDisconnected() is not allowed in UnconnectedState` – ratchet freak Nov 13 '13 at 15:09
  • @ratchetfreak But that error is because it thinks it is already disconnected, that's why it says `not allowed in UnconnectedState`, when in fact it is still connected, the other side has not received the disconnected signal. And as I said, this doesn't happen in Qt4. – sashoalm Nov 13 '13 at 15:09
  • Maybe you should report this in Qt's Bug-Tracker: https://bugreports.qt-project.org If you have done that already, maybe you could share the link here as a comment? – Ignitor Jul 28 '14 at 11:34

0 Answers0