к каталогу

📦 SingleApplication/ itay-grudev

Replacement of QtSingleApplication for Qt 5 and Qt 6 with support for inter-instance communication.

Открыть на GitHubобновлён 1мес назад
Звёзды
1.0k
Форки
241
За неделю
За месяц
Рост %
Язык
C++

Установка и запуск

Usage

The SingleApplication class inherits from whatever Q[Core|Gui]Application class you specify via the QAPPLICATION_CLASS macro (QCoreApplication is the default). Further usage is similar to the use of the Q[Core|Gui]Application classes.

You can use the library as if you use any other QCoreApplication derived class:

#include <QApplication>
#include <SingleApplication.h>

int main( int argc, char* argv[] )
{
    SingleApplication app( argc, argv );

    return app.exec();
}

To include the library files I would recommend that you add it as a git submodule to your project. Here is how:

git submodule add https://github.com/itay-grudev/SingleApplication.git singleapplication

Qmake:

Then include the singleapplication.pri file in your .pro project file.

include(singleapplication/singleapplication.pri)
DEFINES += QAPPLICATION_CLASS=QApplication

CMake:

Then include the subdirectory in your CMakeLists.txt project file.

set(QAPPLICATION_CLASS QApplication CACHE STRING "Inheritance class for SingleApplication")
add_subdirectory(src/third-party/singleapplication)
target_link_libraries(${PROJECT_NAME} SingleApplication::SingleApplication)

Directly including this repository as a Git submodule, or even just a shallow copy of the source code into new projects might not be ideal when using CMake. Another option is using CMake's FetchContent module, available since version 3.11.


# Define the minumun CMake version, as an example 3.24
cmake_minimum_required(VERSION 3.24)

# Include the module
include(FetchContent)

# If using Qt6, override DEFAULT_MAJOR_VERSION
set(QT_DEFAULT_MAJOR_VERSION 6 CACHE STRING "Qt version to use, defaults to 6")

…

Из README репозитория · полный README на GitHub

Теги

applicationc-plus-pluscpphacktoberfestqtqt5qt6qtsingleapplicationsingleapplicationsingletonsubsequent-instances