fix: single app does not works under windows

This commit is contained in:
Gary Wang 2020-04-11 23:16:24 +08:00
parent 14d20fd925
commit 98d352a7c1
2 changed files with 17 additions and 5 deletions

View File

@ -13,7 +13,7 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Widgets Multimedia REQUIRED)
find_package(Qt5 COMPONENTS Widgets Multimedia Network REQUIRED)
set (EXE_NAME pmusic)
@ -35,7 +35,15 @@ add_executable(${EXE_NAME}
ID3v2Pic.h
)
target_link_libraries(${EXE_NAME} PRIVATE Qt5::Widgets Qt5::Multimedia)
target_link_libraries(${EXE_NAME} PRIVATE Qt5::Widgets Qt5::Multimedia Qt5::Network)
# Extra build settings
if (WIN32)
set_property (
TARGET ${EXE_NAME}
PROPERTY WIN32_EXECUTABLE true
)
endif ()
# Helper macros for install settings
macro (pmusic_convert_to_relative_path _var)

View File

@ -16,6 +16,7 @@ void SingleApplicationManager::on_localSocket_newConnection()
QScopedPointer<QLocalSocket> socket(m_localServer->nextPendingConnection());
if (socket) {
socket->waitForReadyRead(500);
QDataStream dataStream(socket.data());
QVariant data;
dataStream.startTransaction();
@ -44,11 +45,14 @@ bool SingleApplicationManager::checkSingleInstance(QVariant data)
QLocalSocket socket;
socket.connectToServer(m_applicationKey);
if (socket.waitForConnected(500)) {
QDataStream dataStream(&socket);
dataStream << data;
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << data;
socket.write(block);
socket.waitForBytesWritten();
socket.close();
socket.flush();
socket.disconnectFromServer();
return true;
}