main.cpp 760 B

12345678910111213141516171819202122232425262728
  1. #include <singleapplication.h>
  2. #include "messagereceiver.h"
  3. int main(int argc, char *argv[])
  4. {
  5. // Allow secondary instances
  6. SingleApplication app( argc, argv, true );
  7. MessageReceiver msgReceiver;
  8. // If this is a secondary instance
  9. if( app.isSecondary() ) {
  10. app.sendMessage( app.arguments().join(' ').toUtf8() );
  11. qDebug() << "App already running.";
  12. qDebug() << "Primary instance PID: " << app.primaryPid();
  13. qDebug() << "Primary instance user: " << app.primaryUser();
  14. return 0;
  15. } else {
  16. QObject::connect(
  17. &app,
  18. &SingleApplication::receivedMessage,
  19. &msgReceiver,
  20. &MessageReceiver::receivedMessage
  21. );
  22. }
  23. return app.exec();
  24. }