#include <singleapplication.h>
Public Slots | |
bool | sendMessage (const QString &message, int timeout=500) |
Signals | |
void | messageReceived (const QString &message) |
Public Member Functions | |
SingleApplication (QObject *parent=0) | |
SingleApplication (const QString &key, QObject *parent=0) | |
virtual | ~SingleApplication () |
QString | key () const |
bool | isRunning () const |
Static Public Member Functions | |
static bool | isRunning (const QString &key) |
static bool | sendMessage (const QString &key, const QString &message, int timeout=500) |
Private Member Functions | |
Q_DISABLE_COPY (SingleApplication) | |
Private Attributes | |
SingleApplicationPrivate *const | d |
The SingleApplication component is basically imitating QtSingleApplication commercial class. Unlike QtSingleApplication the SingleApplication implementation uses Shared Memory to detect a running instance and so-called "Local Sockets" to communicate with it.
SingleApplication::SingleApplication | ( | QObject * | parent = 0 |
) | [explicit] |
Creates a SingleApplication object with the parent parent and the default key.
SingleApplication::SingleApplication | ( | const QString & | key, | |
QObject * | parent = 0 | |||
) | [explicit] |
SingleApplication::~SingleApplication | ( | ) | [virtual] |
The destructor destroys the SingleApplication object, but the underlying shared memory and local server are not removed from the system unless application exit.
Note: If another instance of application with the same key is started again it WILL find this instance.
bool SingleApplication::isRunning | ( | const QString & | key | ) | [static] |
This is an overloaded static member function, provided for convenience.
Returns true if another instance of this application has started; otherwise returns false.
bool SingleApplication::isRunning | ( | ) | const |
Returns true if another instance of this application has started; otherwise returns false.
This function does not find instances of this application that are being run by a different user.
QString SingleApplication::key | ( | ) | const |
Returns the key of this single application.
void SingleApplication::messageReceived | ( | const QString & | message | ) | [signal] |
This signal is emitted when the current instance receives a message from another instance of this application.
SingleApplication::Q_DISABLE_COPY | ( | SingleApplication | ) | [private] |
bool SingleApplication::sendMessage | ( | const QString & | message, | |
int | timeout = 500 | |||
) | [slot] |
Tries to send the text message to the currently running instance. The SingleApplication object in the running instance will emit the messageReceived() signal when it receives the message.
This function returns true if the message has been sent to, and processed by, the current instance. If there is no instance currently running, or if the running instance fails to process the message within timeout milliseconds this function return false.
bool SingleApplication::sendMessage | ( | const QString & | key, | |
const QString & | message, | |||
int | timeout = 500 | |||
) | [static] |
This is an overloaded static member function, provided for convenience.
Tries to send the text message to the currently running instance.
SingleApplicationPrivate* const SingleApplication::d [private] |