[Qt-interest] (QtSolutions) SendMessage() of QtSingleApplication retuns false although main instance received the sent message
Marc
cpmarc at gmail.com
Mon Feb 28 20:45:09 CET 2011
Hello,
We are using QtSolution QtSingleApplication in our application to have only
one instance executing. We have discovered that when there is another
instance runing, in some cases sendMessage (method used to comunicate with
the main instance) function return false, although the main instance has
received the message.
Debugging QtSingleApplication we have observed that
socket.waitForReadyRead(timeout); (line 161) in function sendMessage returns
false sometimes. We believe the problem is when the secondary instance reach
this point, the main instance has closed the socket in which the message has
been received, and when the secondary instance try to read from socket gets
an error. To reproduce this behavior We have put a sleep of 250ms before
socket.waitForReadyRead(timeout); line and then then always sendMessage
return false although main instance has receveid the message.
To avoid this error the solution what we suggest is main instance wait for
delete socket until the secondary instance has disconnected, this can be
done calling method socket->waitForDisconnected(2000); after
socket->waitForBytesWritten(1000) (line 196) in function
receiveConnection(), by this way secondary instance always will be able to
read the confirmation that main instance has received the message.
We have wrote a small program to reproduce the bug described, that if
another instance is running send to the main instance current date/time and
the main instance shows it with a QMessageBox, if the sendMessage method
return false a QMessageBox is thrown notifying the error. Executing it twice
times is enough to reproducte the bug. We have put an sleep before call
socket.waitForReadyRead(timeout) to force bug appears always, and
uncommenting line 205 the bug is solved with our solution.
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110228/4882b8a6/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QtSingleApplicationBugFail.7z
Type: application/octet-stream
Size: 10672 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110228/4882b8a6/attachment.obj
More information about the Qt-interest-old
mailing list