* @brief SingleApplication::SingleApplication this replaces the QApplication * allowing for local socket based communications. * @param argc * @param argv * @param uniqueKey */
| 15 | * @param uniqueKey |
| 16 | */ |
| 17 | SingleApplication::SingleApplication(int &argc, char *argv[], QString uniqueKey) |
| 18 | : QApplication(argc, argv), _uniqueKey(std::move(uniqueKey)) { |
| 19 | sharedMemory.setKey(_uniqueKey); |
| 20 | if (sharedMemory.attach()) { |
| 21 | _isRunning = true; |
| 22 | } else { |
| 23 | _isRunning = false; |
| 24 | // create shared memory. |
| 25 | if (!sharedMemory.create(1)) { |
| 26 | #ifdef QT_DEBUG |
| 27 | dbg() << "Unable to create single instance."; |
| 28 | #endif |
| 29 | return; |
| 30 | } |
| 31 | // create local server and listen to incomming messages from other |
| 32 | // instances. |
| 33 | localServer.reset(new QLocalServer(this)); |
| 34 | connect(localServer.data(), &QLocalServer::newConnection, this, |
| 35 | &SingleApplication::receiveMessage); |
| 36 | localServer->listen(_uniqueKey); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // public slots. |
| 41 |