diff options
Diffstat (limited to 'examples/sending_arguments')
-rwxr-xr-x | examples/sending_arguments/main.cpp | 25 | ||||
-rw-r--r-- | examples/sending_arguments/messagereceiver.cpp | 12 | ||||
-rw-r--r-- | examples/sending_arguments/messagereceiver.h | 15 | ||||
-rwxr-xr-x | examples/sending_arguments/sending_arguments.pro | 9 |
4 files changed, 61 insertions, 0 deletions
diff --git a/examples/sending_arguments/main.cpp b/examples/sending_arguments/main.cpp new file mode 100755 index 0000000..8368036 --- /dev/null +++ b/examples/sending_arguments/main.cpp @@ -0,0 +1,25 @@ +#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(); +} diff --git a/examples/sending_arguments/messagereceiver.cpp b/examples/sending_arguments/messagereceiver.cpp new file mode 100644 index 0000000..0560b07 --- /dev/null +++ b/examples/sending_arguments/messagereceiver.cpp @@ -0,0 +1,12 @@ +#include <QDebug> +#include "messagereceiver.h" + +MessageReceiver::MessageReceiver(QObject *parent) : QObject(parent) +{ +} + +void MessageReceiver::receivedMessage(int instanceId, QByteArray message) +{ + qDebug() << "Received message from instance: " << instanceId; + qDebug() << "Message Text: " << message; +} diff --git a/examples/sending_arguments/messagereceiver.h b/examples/sending_arguments/messagereceiver.h new file mode 100644 index 0000000..50a970c --- /dev/null +++ b/examples/sending_arguments/messagereceiver.h @@ -0,0 +1,15 @@ +#ifndef MESSAGERECEIVER_H +#define MESSAGERECEIVER_H + +#include <QObject> + +class MessageReceiver : public QObject +{ + Q_OBJECT +public: + explicit MessageReceiver(QObject *parent = 0); +public slots: + void receivedMessage( int instanceId, QByteArray message ); +}; + +#endif // MESSAGERECEIVER_H diff --git a/examples/sending_arguments/sending_arguments.pro b/examples/sending_arguments/sending_arguments.pro new file mode 100755 index 0000000..897636a --- /dev/null +++ b/examples/sending_arguments/sending_arguments.pro @@ -0,0 +1,9 @@ +# Single Application implementation +include(../../singleapplication.pri) +DEFINES += QAPPLICATION_CLASS=QCoreApplication + +SOURCES += main.cpp \ + messagereceiver.cpp + +HEADERS += \ + messagereceiver.h |