forked from itay-grudev/SingleApplication
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an example of an application sending it's arguments to the prim…
…ary instance
- Loading branch information
1 parent
6f58597
commit 596cf23
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Single Application implementation | ||
include(../../singleapplication.pri) | ||
DEFINES += QAPPLICATION_CLASS=QCoreApplication | ||
|
||
SOURCES += main.cpp \ | ||
messagereceiver.cpp | ||
|
||
HEADERS += \ | ||
messagereceiver.h |