main.cpp 772 B

1234567891011121314151617181920212223242526
  1. #include "messagereceiver.h"
  2. #include <singleapplication.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(&app,
  17. &SingleApplication::receivedMessage,
  18. &msgReceiver,
  19. &MessageReceiver::receivedMessage);
  20. }
  21. return app.exec();
  22. }