mirror of
https://github.com/itay-grudev/SingleApplication.git
synced 2024-11-15 20:25:43 +08:00
f975da90cc
* Fix send message example If a secondary instance sends a message immediately after connecting, the message follows the init message. This causes the slotConnectionEstablished to read and consume the tail of the message and interpret it as the checksum. The checksum fails and the connection becomes invalid. To avoid this race, we prefix the init message with its length. This way, we consume only the data relevant to the init message. This patch fixes the sending_arguments example. Signed-off-by: Francis Giraldeau <francis.giraldeau@gmail.com> * Fix include file case Signed-off-by: Francis Giraldeau <francis.giraldeau@nrc-cnrc.gc.ca>
26 lines
582 B
C++
Executable File
26 lines
582 B
C++
Executable File
#include <singleapplication.h>
|
|
#include "messagereceiver.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
// Allow secondary instances
|
|
SingleApplication app( argc, argv, true );
|
|
|
|
MessageReceiver msgReceiver;
|
|
|
|
// If this is a secondary instance
|
|
if( app.isSecondary() ) {
|
|
app.sendMessage( app.arguments().join(' ').toUtf8() );
|
|
return 0;
|
|
} else {
|
|
QObject::connect(
|
|
&app,
|
|
&SingleApplication::receivedMessage,
|
|
&msgReceiver,
|
|
&MessageReceiver::receivedMessage
|
|
);
|
|
}
|
|
|
|
return app.exec();
|
|
}
|