|
SingleApplication
3.6.0
Replacement for QtSingleApplication
|
Handles multiple instances of the same Application. More...
#include <singleapplication.h>
Public Types | |
| enum | Mode { User = 1 << 0 , System = 1 << 1 , SecondaryNotification = 1 << 2 , ExcludeAppVersion = 1 << 3 , ExcludeAppPath = 1 << 4 } |
Mode of operation of SingleApplication. Whether the block should be user-wide or system-wide and whether the primary instance should be notified when a secondary instance had been started. More... | |
| enum | SendMode { NonBlocking , BlockUntilPrimaryExit } |
| Mode of operation of sendMessage. More... | |
Signals | |
| void | instanceStarted () |
Triggered whenever a new instance had been started, except for secondary instances if the Mode::SecondaryNotification flag is not specified. | |
| void | receivedMessage (quint32 instanceId, QByteArray message) |
| Triggered whenever there is a message received from a secondary instance. | |
Public Member Functions | |
| SingleApplication (int &argc, char *argv[], bool allowSecondary=false, Options options=Mode::User, int timeout=1000, const QString &userData={}) | |
Intitializes a SingleApplication instance with argc command line arguments in argv. More... | |
| bool | isPrimary () const |
| Checks if the instance is primary instance. More... | |
| bool | isSecondary () const |
| Checks if the instance is a secondary instance. More... | |
| quint32 | instanceId () const |
| Returns a unique identifier for the current instance. More... | |
| qint64 | primaryPid () const |
| Returns the process ID (PID) of the primary instance. More... | |
| QString | primaryUser () const |
| Returns the username of the user running the primary instance. More... | |
| QString | currentUser () const |
| Returns the username of the current user. More... | |
| bool | sendMessage (const QByteArray &message, int timeout=100, SendMode sendMode=NonBlocking) |
| Sends a message to the primary instance. More... | |
| QStringList | userData () const |
| Get the set user data. More... | |
Handles multiple instances of the same Application.
Mode of operation of SingleApplication. Whether the block should be user-wide or system-wide and whether the primary instance should be notified when a secondary instance had been started.
| Enumerator | |
|---|---|
| User | The |
| System | The |
| SecondaryNotification | Whether to trigger |
| ExcludeAppVersion | Excludes the application version from the server name (and memory block) hash |
| ExcludeAppPath | Excludes the application path from the server name (and memory block) hash |
|
explicit |
Intitializes a SingleApplication instance with argc command line arguments in argv.
SingleApplication block to be applied User wide or System wide. Mode::SecondaryNotification only works if set on both the primary instance and the secondary instance. SingleApplication initialisation will be completed in given time, though is a good hint. Usually 4*timeout would be the worst case (fail) scenario. QAPPLICATION_CLASS constructor for reference | QString SingleApplication::currentUser | ( | ) | const |
Returns the username of the current user.
| quint32 SingleApplication::instanceId | ( | ) | const |
Returns a unique identifier for the current instance.
| bool SingleApplication::isPrimary | ( | ) | const |
Checks if the instance is primary instance.
true if the instance is primary | bool SingleApplication::isSecondary | ( | ) | const |
Checks if the instance is a secondary instance.
true if the instance is secondary | qint64 SingleApplication::primaryPid | ( | ) | const |
Returns the process ID (PID) of the primary instance.
| QString SingleApplication::primaryUser | ( | ) | const |
Returns the username of the user running the primary instance.
| bool SingleApplication::sendMessage | ( | const QByteArray & | message, |
| int | timeout = 100, |
||
| SendMode | sendMode = NonBlocking |
||
| ) |
Sends a message to the primary instance.
| message | data to send |
| timeout | timeout for connecting |
| sendMode | - Mode of operation |
true on success | QStringList SingleApplication::userData | ( | ) | const |
Get the set user data.