try singleapplication

This commit is contained in:
Martin Brodbeck 2019-04-10 12:04:18 +02:00
parent 5a3b6fff82
commit ecc45811d8
4 changed files with 20 additions and 5 deletions

3
.gitmodules vendored
View file

@ -1,3 +1,6 @@
[submodule "3rdparty/nlohmann_json"]
path = 3rdparty/nlohmann_json
url = https://github.com/nlohmann/json.git
[submodule "3rdparty/singleapplication"]
path = 3rdparty/singleapplication
url = git@github.com:itay-grudev/SingleApplication.git

1
3rdparty/singleapplication vendored Submodule

@ -0,0 +1 @@
Subproject commit 7163d166a1fbce7917015293f8e139bd65604881

View file

@ -11,6 +11,11 @@ set(CMAKE_AUTORCC ON)
find_package(Qt5Widgets CONFIG REQUIRED)
find_package(Qt5PrintSupport CONFIG REQUIRED)
# For SingleApplication:
find_package(Qt5Network CONFIG REQUIRED)
set(QAPPLICATION_CLASS QApplication)
add_compile_definitions(QAPPLICATION_CLASS=${QAPPLICATION_CLASS})
set(GUI_SOURCES
kima2.cpp
mainwindow.cpp
@ -28,11 +33,14 @@ set(GUI_SOURCES
settingsdialog.cpp
settingsdialog.ui
../../kima2.qrc
${PROJECT_SOURCE_DIR}/3rdparty/singleapplication/singleapplication.cpp
${PROJECT_SOURCE_DIR}/3rdparty/singleapplication/singleapplication_p.cpp
)
add_executable(kima2 ${GUI_SOURCES} kima2.rc)
target_include_directories(kima2 PRIVATE ${PROJECT_BINARY_DIR})
target_link_libraries(kima2 core printer Qt5::Widgets Qt5::PrintSupport stdc++fs)
target_include_directories(kima2 PRIVATE ${PROJECT_SOURCE_DIR}/3rdparty/singleapplication)
target_link_libraries(kima2 core printer Qt5::Widgets Qt5::PrintSupport Qt5::Network stdc++fs)
if(WIN32)
set_target_properties(kima2 PROPERTIES LINK_FLAGS "-mwindows")
endif(WIN32)

View file

@ -6,12 +6,14 @@
#include <QLibraryInfo>
#include <QMessageBox>
#include <QSettings>
#include <QTranslator>
#include <QSharedMemory>
#include <QTranslator>
#include <singleapplication.h>
int main(int argc, char* argv[])
{
QApplication kimaApp{argc, argv};
SingleApplication kimaApp(argc, argv);
// QCoreApplication::setOrganizationName("RustySoft");
QCoreApplication::setOrganizationDomain("rustysoft.de");
@ -19,10 +21,11 @@ int main(int argc, char* argv[])
// Make sure that only one instance of the application runs
// Of course the uuid used here is unique to this application
QSharedMemory shared("26297455-946a-4607-bfb7-5025a5f1e136");
// (commented out in favour of SingleApplication)
/*QSharedMemory shared("26297455-946a-4607-bfb7-5025a5f1e136");
if (!shared.create(512, QSharedMemory::ReadWrite)) {
exit(0);
}
}*/
QTranslator qTranslator;
QLocale german(QLocale::German);