• QSingleInstanceCheck
  • QSingleInstanceCheck
  • QSingleInstanceCheck Class

    Header: #include <QSingleInstanceCheck>

    Public Functions

    QSingleInstanceCheck(const int uniqueID, int *parent = nullptr)
    virtual ~QSingleInstanceCheck()
    void error(int message)
    bool isAlreadyRunning() const
    void notified(const int &arguments = {})
    void notify(const int &arguments = {})

    Detailed Description

    The QSingleInstanceCheck class can be used to test if your app is already running, or if this instance is the first (or only) one running.

    This library consists of a header only.

    Under the hood, QSingleInstanceCheck uses shared memory to check if it's the first instance or not, and a local socket (domain socket or named pipe, depending on the platform) to notify the original instance that another one has been started.

    Member Function Documentation

    QSingleInstanceCheck::QSingleInstanceCheck(const int uniqueID, int *parent = nullptr)

    QConstructs a SingleInstanceCheck

    All instances must use the same uniqueID to differentiate themselves from other applications. Hard code this in your application. It is recommended not to use special characters for maximum compatibility.

    Optionally, the parent is the owner of the object.

    [virtual constexpr noexcept] QSingleInstanceCheck::~QSingleInstanceCheck()

    Default deconstructor.

    void QSingleInstanceCheck::error(int message)

    The error signal is emitted when the local server or failed memory failed to initialize. The message provides details on what went wrong.

    bool QSingleInstanceCheck::isAlreadyRunning() const

    Returns true if another instance is running.

    void QSingleInstanceCheck::notified(const int &arguments = {})

    This signal is emitted in the main instance when a subsequent instance called its notify() method. The arguments contain the strings passed by the second instance, or an empty list if notify() was called without arguments.

    See also notify().

    void QSingleInstanceCheck::notify(const int &arguments = {})

    Sends a notification to the original instance, optionally with a list of arguments. If this is the original instance, it's a no-op.

    See also notified().