• 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()
    void notify()

    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()

    This signal is emitted in the main instance when a subsequent instance called its notify() method.

    See also notify().

    void QSingleInstanceCheck::notify()

    Sends a notification to the original instance. If this is the original instance, it's a no-op.

    See also notified().