{"id":16608441,"url":"https://github.com/oclero/qtappinstancemanager","last_synced_at":"2025-07-04T13:06:38.401Z","repository":{"id":64795850,"uuid":"425198956","full_name":"oclero/qtappinstancemanager","owner":"oclero","description":"Single application instance manager for Qt6.","archived":false,"fork":false,"pushed_at":"2025-03-15T11:03:04.000Z","size":64,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-31T09:41:54.425Z","etag":null,"topics":["cmake","cpp","cpp17","qt","qt6","single-instance-app"],"latest_commit_sha":null,"homepage":"https://github.com/oclero/qtappinstancemanager","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oclero.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-11-06T09:01:43.000Z","updated_at":"2025-04-04T20:28:17.000Z","dependencies_parsed_at":"2025-05-31T00:20:02.204Z","dependency_job_id":"a3a6fefe-6c48-48d0-be14-7c5777924ad0","html_url":"https://github.com/oclero/qtappinstancemanager","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/oclero/qtappinstancemanager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oclero%2Fqtappinstancemanager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oclero%2Fqtappinstancemanager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oclero%2Fqtappinstancemanager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oclero%2Fqtappinstancemanager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oclero","download_url":"https://codeload.github.com/oclero/qtappinstancemanager/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oclero%2Fqtappinstancemanager/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263548654,"owners_count":23478808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmake","cpp","cpp17","qt","qt6","single-instance-app"],"created_at":"2024-10-12T01:26:14.353Z","updated_at":"2025-07-04T13:06:38.392Z","avatar_url":"https://github.com/oclero.png","language":"C++","readme":"\u003cdiv align=\"center\"\u003e\n\t\u003cimg height=\"50\" src=\"branding/logo.svg\"\u003e\n\u003c/div\u003e\n\n# QtAppInstanceManager\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green)](https://mit-license.org/)\n[![CMake version](https://img.shields.io/badge/CMake-3.21+-064F8C?logo=cmake)](https://www.qt.io)\n[![C++ version](https://img.shields.io/badge/C++-17-00599C?logo=++)](https://www.qt.io)\n[![Qt version](https://img.shields.io/badge/Qt-6.6.0+-41CD52?logo=qt)](https://www.qt.io)\n\n**QtAppInstanceManager** is a tool to control how many instances of your Qt application are running at the same time, and to send messages between instances. It uses a local socket under the hood. You may then build upon this foundation any messaging system or protocol, such as JSON-RPC for instance (NB: not provided because out of the scope of this library).\n\nIt is intended to be a replacement for `QtSingleApplication`, the deprecated Qt4 official project.\n\nAlso, it differs from [itay-grudev's SingleApplication](https://github.com/itay-grudev/SingleApplication) because you don't need to inherit a child class of `QCoreApplication` to use `QtAppInstanceManager`, therefore it doesn't need configure-time flags and macros.\n\n---\n\n### Table of Contents\n\n- [Requirements](#requirements)\n- [Usage](#usage)\n- [Examples](#examples)\n  - [Single application](#single-application)\n  - [Multiple application instances](#multiple-application-instances)\n- [Author](#author)\n- [License](#license)\n\n---\n\n## Requirements\n\n- Platform: Windows, MacOS, Linux.\n- [CMake 3.21+](https://cmake.org/download/)\n- [Qt 6.6+](https://www.qt.io/download-qt-installer)\n\n## Usage\n\n1. Add the library as a dependency in your CMakeLists.txt, for example with FetchContent.\n\n   ```cmake\n   include(FetchContent)\n   FetchContent_Declare(QtAppInstanceManager\n    GIT_REPOSITORY \"https://github.com/oclero/qtappinstancemanager.git\"\n   )\n   FetchContent_MakeAvailable(QtAppInstanceManager)\n   ```\n\n2. Link with the library in CMake.\n\n   ```cmake\n   target_link_libraries(your_project oclero::QtAppInstanceManager)\n   ```\n\n3. Include the only necessary header in your C++ file.\n\n   ```c++\n   #include \u003coclero/QtAppInstanceManager.hpp\u003e\n   ```\n\n## Examples\n\n### Single application\n\nJust create an `oclero::QtAppInstanceManager` and configure it to allow only one instance running at the same time with `setForceSingleInstance(true)`.\n\nComplete example can be found in the [`/examples` directory](examples/single), including CMake and C++ file.\n\n```c++\n// Initialize instance manager to force only one instance running.\noclero::QtAppInstanceManager instanceManager;\ninstanceManager.setMode(QtAppInstanceManager::Mode::SingleInstance);\n\n// When another instance will start, it will immediately quit the app and send its\n// arguments to the primary instance.\nQObject::connect(\u0026instanceManager,\n  \u0026oclero::QtAppInstanceManager::secondaryInstanceMessageReceived,\n  \u0026instanceManager,\n  [](const unsigned int id, QByteArray const\u0026 data) {\n    // Do what you want:\n    // - Raise the main window.\n    // - Open a file in an another tab of your main window.\n    // - ...\n    qDebug() \u003c\u003c \"Secondary instance message received: \" \u003c\u003c data;\n  });\n\n// If you don't want for the app to quit, you can set the manual mode and handle this step by yourself.\ninstanceManager.setAppExitMode(QtAppInstanceManager::AppExitMode::Manual);\nQObject::connect(\u0026instanceManager,\n  \u0026QtAppInstanceManager::appExitRequested,\n  \u0026singleInstance,\n  []() {\n    // Do what you want.\n    // Usually you should quit the app.\n    qDebug() \u003c\u003c \"This app should exit\";\n    QCoreApplication::quit();\n    std::exit(EXIT_SUCCESS);\n  });\n```\n\n### Multiple application instances\n\n```c++\noclero::QtAppInstanceManager instanceManager;\n\n// If we are the FIRST instance to launch,\n// we'll receive messages from other instances that will launch after us.\nQObject::connect(\u0026instanceManager,\n                 \u0026oclero::QtAppInstanceManager::secondaryInstanceMessageReceived,\n                 \u0026instanceManager,\n  [](const unsigned int id, QByteArray const\u0026 data) {\n    qDebug() \u003c\u003c \"Message received from secondary instance: \" \u003c\u003c data;\n  });\n\n// If we are another instance, we are able to receive messages from the primary one.\nQObject::connect(\u0026instanceManager,\n                 \u0026oclero::QtAppInstanceManager::primaryInstanceMessageReceived,\n                 \u0026instanceManager,\n  [](QByteArray const\u0026 data) {\n    qDebug() \u003c\u003c \"Message received from primary instance: \" \u003c\u003c data;\n  });\n\n// If ever the first instance to launch unexpectly shuts down,\n// one of the secondary instances will immediately take of the role of the primary one.\nQObject::connect(\u0026instanceManager,\n                 \u0026oclero::QtAppInstanceManager::instanceRoleChanged,\n                 \u0026instanceManager,\n  [\u0026instanceManager]() {\n    // There is a short period of time before roles are assigned again.\n    if (!instanceManager.isPrimaryInstance() \u0026\u0026 !instanceManager.isSecondaryInstance()) {\n      qDebug() \u003c\u003c \"Waiting for new role...\";\n    } else {\n      qDebug() \u003c\u003c \"New role: \" \u003c\u003c (instanceManager.isPrimaryInstance() ? \"Primary\" : \"Secondary\");\n    }\n  });\n```\n\n## Author\n\n**Olivier Cléro** | [email](mailto:oclero@pm.me) | [website](https://www.olivierclero.com) | [github](https://www.github.com/oclero)\n\nThanks to [Emilien Vallot](https://github.com/envt) for his help and advices.\n\n## License\n\n**QtAppInstanceManager** is available under the MIT license. See the [LICENSE](LICENSE) file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foclero%2Fqtappinstancemanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foclero%2Fqtappinstancemanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foclero%2Fqtappinstancemanager/lists"}