16 : QApplication(argc, argv), _uniqueKey(std::move(uniqueKey)) {
17 sharedMemory.setKey(_uniqueKey);
18 if (sharedMemory.attach()) {
23 if (!sharedMemory.create(1)) {
25 dbg() <<
"Unable to create single instance.";
31 localServer.reset(
new QLocalServer(
this));
32 connect(localServer.data(), &QLocalServer::newConnection,
this,
34 localServer->listen(_uniqueKey);
45 QLocalSocket *localSocket = localServer->nextPendingConnection();
46 if (!localSocket->waitForReadyRead(timeout)) {
48 dbg() << localSocket->errorString().toLatin1();
52 QByteArray byteArray = localSocket->readAll();
53 QString message = QString::fromUtf8(byteArray.constData());
55 localSocket->disconnectFromServer();
75 QLocalSocket localSocket(
this);
76 localSocket.connectToServer(_uniqueKey, QIODevice::WriteOnly);
77 if (!localSocket.waitForConnected(timeout)) {
79 dbg() << localSocket.errorString().toLatin1();
83 localSocket.write(message.toUtf8());
84 if (!localSocket.waitForBytesWritten(timeout)) {
86 dbg() << localSocket.errorString().toLatin1();
90 localSocket.disconnectFromServer();
bool isRunning()
SingleApplication::isRunning is there already a QtPass instance running, to check wether to be server...
void receiveMessage()
SingleApplication::receiveMessage we have received (a command line) message.
SingleApplication(int &argc, char *argv[], QString uniqueKey)
SingleApplication::SingleApplication this replaces the QApplication allowing for local socket based c...
bool sendMessage(const QString &message)
SingleApplication::sendMessage send a message (from commandline) to an already running QtPass instanc...
void messageAvailable(QString message)
messageAvailable notification from commandline