Giter Site home page Giter Site logo

alfredoramos / singleapplication Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 75 KB

Single application library for Qt without network dependency

License: GNU General Public License v3.0

QMake 27.62% C++ 31.24% CMake 41.14%
single-application single-instance qt library cpp

singleapplication's Introduction

About

Single application library for Qt without network dependency. Based on Dmitry Sazonov's code.

Build Status Latest Stable Version Code Quality License

Dependencies

  • Qt >= 5.9.2
  • C++11 compiler support

Build

Subproject

If you want to use the library directly inside your application source code, you can use any of the following methods:

QMake subproject

Include the singleapplication.pri file within your project file:

include(singleapplication/singleapplication.pri)
CMake subproject

Include the singleapplication directory and add the library on your CMakeLists.txt file:

add_subdirectory(singleapplication)
target_link_libraries(YOUR_TARGET singleapplication)

System library

First you will need to get the sources and create a build directory. In-source builds are not allowed.

git clone https://github.com/AlfredoRamos/singleapplication.git
cd singleapplication
mkdir build
cd build

After that, you can use any of the following methods to build and install the library on your system.

QMake build
qmake ../ CONFIG+=release
make
make INSTALL_ROOT="pkg" install

Note: If you also want to generate the pkg-config file, use the following qmake command instead:

qmake ../ CONFIG+=release CONFIG+=pkgconfig

Once the files are installed on your system, add the library in your project file:

LIBS += -lsingleapplication

Alternatively, if you built the library with the CONFIG+=pkgconfig flag, you can use the library with pkg-config:

CONFIG += link_pkgconfig
PKGCONFIG += singleapplication
CMake build
cmake -S ../ -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release
cmake --build . --clean-first
cmake --install . --prefix pkg/usr/ --strip

Note: If you also want to generate the pkg-config file, replace the first cmake command with the following:

cmake -S ../ -DCMAKE_INSTALL_PREFIX=/usr -DGENERATE_PKG_CONFIG=ON -DCMAKE_BUILD_TYPE=Release

Once the files are installed on your system, add the library in your CMakeLists.txt file:

find_package(singleapplication REQUIRED)
target_link_libraries(YOUR_TARGET singleapplication)

Alternatively, if you built the library with the -DGENERATE_PKG_CONFIG=ON flag, you can use the library with pkg-config:

find_package(PkgConfig REQUIRED)
pkg_check_modules(singleapplication REQUIRED IMPORTED_TARGET singleapplication)
target_link_libraries(YOUR_TARGET PkgConfig::singleapplication)

Usage

In the main.cpp file of your Qt/C++ application include the library, create a new instance of SingleApplication, and add a check if another instance is already running using SingleApplication::createInstance():

// Subproject
//#include "singleapplication.hpp"

// System library
//#include <singleapplication.hpp>

int main(int argc, char *argv[])
{
	SingleApplication *guard = new SingleApplication("key_string");

	if (!guard->createInstance()) {
		// Another instance of this application is already running
		return 0;
	}

	QApplication a(argc, argv);
	//...
}

The constructor of the SingleApplication class only accepts one parameter and must be a QString.

You can specify random generated QString or using information from the application, like QCoreApplication::applicationName().

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.