From 7db03beb208bc9ee5dc8bc1243775f4aca8ebf67 Mon Sep 17 00:00:00 2001 From: Leandro Nini Date: Fri, 16 Apr 2021 14:22:21 +0200 Subject: [PATCH] Fix sending message to other instance --- src/singleApp.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/singleApp.cpp b/src/singleApp.cpp index 49ecc51..e54909e 100644 --- a/src/singleApp.cpp +++ b/src/singleApp.cpp @@ -22,10 +22,6 @@ #include "utils.h" #include "xdg.h" -#ifdef _WIN32 -# include -#endif - #include #include @@ -39,7 +35,7 @@ singleApp::singleApp(int & argc, char ** argv) : bool singleApp::isRunning() { #ifdef _WIN32 - const QString fifoFileName("\\\\.\\pipe\\musiqt.fifo"); + const QString fifoFileName(R"(\\.\pipe\musiqt.fifo)"); #else const QString fifoFileName(QString("%1/.musiqt.fifo").arg(xdg::getRuntimeDir())); #endif @@ -90,6 +86,7 @@ bool singleApp::isRunning() qint64 res = socket.write(block); qDebug() << "res: " << res; socket.flush(); + socket.waitForBytesWritten(); socket.disconnectFromServer(); } else @@ -125,17 +122,18 @@ void singleApp::acceptMessage() return; } - socket->waitForReadyRead(); - - qDebug() << "data: " << socket->bytesAvailable(); - QDataStream in(socket); - in.setVersion(QDataStream::Qt_4_0); - QString message; - in >> message; - qDebug() << "msg: " << message; + if (socket->waitForReadyRead()) + { + qDebug() << "data: " << socket->bytesAvailable(); + QDataStream in(socket); + in.setVersion(QDataStream::Qt_4_0); + QString message; + in >> message; + qDebug() << "msg: " << message; - if (!message.isEmpty()) - emit sendMessage(message); + if (!message.isEmpty()) + emit sendMessage(message); + } delete socket; }