<p>The <ahref="qtsingleapplication.html">QtSingleApplication</a> component provides support for applications that can be only started once per user.</p>
<p>For some applications it is useful or even critical that they are started only once by any user. Future attempts to start the application should activate any already running instance, and possibly perform requested actions, e.g. loading a file, in that instance.</p>
<p>The <ahref="qtsingleapplication.html">QtSingleApplication</a> class provides an interface to detect a running instance, and to send command strings to that instance. For console (non-GUI) applications, the <ahref="qtsinglecoreapplication.html">QtSingleCoreApplication</a> variant is provided, which avoids dependency on <ahref="http://qt.nokia.com/doc/4.6/qtgui.html">QtGui</a>.</p>
<p>The user interface in this application is a <ahref="http://qt.nokia.com/doc/4.6/qmainwindow.html">QMainWindow</a> subclass with a <ahref="http://qt.nokia.com/doc/4.6/qmdiarea.html">QMdiArea</a> as the central widget. It implements a slot <tt>handleMessage()</tt> that will be connected to the messageReceived() signal of the <ahref="qtsingleapplication.html">QtSingleApplication</a> class.</p>
<pre> MainWindow::MainWindow()
{
workspace = new QMdiArea(this);
setCentralWidget(workspace);
}</pre>
<p>The <ahref="http://qt.nokia.com/doc/4.6/designer-to-know.html">MainWindow</a> constructor creates a minimal user interface.</p>
if (message.toLower().startsWith("/print ")) {
filename = filename.mid(7);
action = Print;
} else if (!message.isEmpty()) {
action = Open;
}
if (action == Nothing) {
emit needToShow();
return;
}
QFile file(filename);
QString contents;
if (file.open(QIODevice::ReadOnly))
contents = file.readAll();
else
contents = "[[Error: Could not load file " + filename + "]]";
QTextEdit *view = new QTextEdit;
view->setPlainText(contents);
switch(action) {</pre>
<p>The handleMessage() slot interprets the message passed in as a filename that can be prepended with <i>/print</i> to indicate that the file should just be printed rather than loaded.</p>
<pre> case Print:
{
QPrinter printer;
view->print(&printer);
delete view;
}
break;
case Open:
{
workspace->addSubWindow(view);
view->setWindowTitle(message);
view->show();
emit needToShow();
}
break;
default:
break;
};
}</pre>
<p>Loading the file will also activate the window.</p>
<p>The <tt>main</tt> entry point function creates a <ahref="qtsingleapplication.html">QtSingleApplication</a> object, and creates a message to send to a running instance of the application. If the message was sent successfully the process exits immediately.</p>
<p>If the message could not be sent the application starts up. Note that <tt>false</tt> is passed to the call to setActivationWindow() to prevent automatic activation for every message received, e.g. when the application should just print a file. Instead, the message handling function determines whether activation is requested, and signals that by emitting the needToShow() signal. This is then simply connected directly to <ahref="qtsingleapplication.html">QtSingleApplication</a>'s activateWindow() slot.</p>
<p>The application in this example has a log-view that displays messages sent by further instances of the same application.</p>
<p>The example demonstrates the use of the <ahref="qtsingleapplication.html">QtSingleApplication</a> class to detect and communicate with a running instance of the application using the sendMessage() API. The messageReceived() signal is used to display received messages in a <ahref="http://qt.nokia.com/doc/4.6/qtextedit.html">QTextEdit</a> log.</p>
<p>The example has only the <tt>main</tt> entry point function. A <ahref="qtsingleapplication.html">QtSingleApplication</a> object is created immediately.</p>
<pre> if (instance.sendMessage("Wake up!"))
return 0;</pre>
<p>If another instance of this application is already running, sendMessage() will succeed, and this instance just exits immediately.</p>
<pre> TextEdit logview;
logview.setReadOnly(true);
logview.show();</pre>
<p>Otherwise the instance continues as normal and creates the user interface.</p>
<p>The <tt>logview</tt> object is also set as the application's activation window. Every time a message is received, the window will be raised and activated automatically.</p>
<p>The messageReceived() signal is also connected to the <ahref="http://qt.nokia.com/doc/4.6/qtextedit.html">QTextEdit</a>'s append() slot. Every message received from further instances of this application will be displayed in the log.</p>
<li><divclass="fn"><b><ahref="http://qt.nokia.com/doc/4.6/qapplication.html#commitData">commitData</a></b> ( QSessionManager & )</div></li>
<li><divclass="fn"><b><ahref="http://qt.nokia.com/doc/4.6/qapplication.html#commitDataRequest">commitDataRequest</a></b> ( QSessionManager & )</div></li>
<li><divclass="fn"><b><ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#processEvents-2">processEvents</a></b> ( QFlags<QEventLoop::ProcessEventsFlag>, int )</div></li>
<li><divclass="fn"><b><ahref="http://qt.nokia.com/doc/4.6/qapplication.html#saveState">saveState</a></b> ( QSessionManager & )</div></li>
<li><divclass="fn"><b><ahref="http://qt.nokia.com/doc/4.6/qapplication.html#saveStateRequest">saveStateRequest</a></b> ( QSessionManager & )</div></li>
<li><divclass="fn"><b><ahref="http://qt.nokia.com/doc/4.6/qapplication.html#autoMaximizeThreshold-prop">setAutoMaximizeThreshold</a></b> ( const int )</div></li>
<li><divclass="fn"><b><ahref="http://qt.nokia.com/doc/4.6/qapplication.html#doubleClickInterval-prop">setDoubleClickInterval</a></b> ( int )</div></li>
<li><divclass="fn"><b><ahref="http://qt.nokia.com/doc/4.6/qapplication.html#keyboardInputInterval-prop">setKeyboardInputInterval</a></b> ( int )</div></li>
</tr></table><h1class="title">Obsolete Members for QtSingleApplication</h1>
<p><b>The following class members are obsolete.</b> They are provided to keep old source code working. We strongly advise against using them in new code.</p>
<p><ul><li><ahref="qtsingleapplication.html">QtSingleApplication class reference</a></li></ul></p>
<tr><tdclass="memItemLeft"align="right"valign="top"></td><tdclass="memItemRight"valign="bottom"><b><ahref="qtsingleapplication.html#QtSingleApplication-3">QtSingleApplication</a></b> ( int &<i>argc</i>, char ** <i>argv</i>, Type <i>type</i> )</td></tr>
<li><divbar="2"class="fn"></div>16 public functions inherited from <ahref="http://qt.nokia.com/doc/4.6/qapplication.html#public-functions">QApplication</a></li>
<li><divbar="2"class="fn"></div>4 public functions inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#public-functions">QCoreApplication</a></li>
<li><divbar="2"class="fn"></div>29 public functions inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#public-functions">QObject</a></li>
<li><divbar="2"class="fn"></div>7 public slots inherited from <ahref="http://qt.nokia.com/doc/4.6/qapplication.html#public-slots">QApplication</a></li>
<li><divbar="2"class="fn"></div>1 public slot inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#public-slots">QCoreApplication</a></li>
<li><divbar="2"class="fn"></div>1 public slot inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#public-slots">QObject</a></li>
<li><divbar="2"class="fn"></div>5 signals inherited from <ahref="http://qt.nokia.com/doc/4.6/qapplication.html#signals">QApplication</a></li>
<li><divbar="2"class="fn"></div>1 signal inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#signals">QCoreApplication</a></li>
<li><divbar="2"class="fn"></div>1 signal inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#signals">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><divclass="fn"></div>13 properties inherited from <ahref="http://qt.nokia.com/doc/4.6/qapplication.html#properties">QApplication</a></li>
<li><divclass="fn"></div>4 properties inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#properties">QCoreApplication</a></li>
<li><divclass="fn"></div>1 property inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#properties">QObject</a></li>
<li><divclass="fn"></div>1 public type inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#public-variables">QObject</a></li>
<li><divclass="fn"></div>73 static public members inherited from <ahref="http://qt.nokia.com/doc/4.6/qapplication.html#static-public-members">QApplication</a></li>
<li><divclass="fn"></div>38 static public members inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#static-public-members">QCoreApplication</a></li>
<li><divclass="fn"></div>4 static public members inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#static-public-members">QObject</a></li>
<li><divclass="fn"></div>1 protected function inherited from <ahref="http://qt.nokia.com/doc/4.6/qapplication.html#protected-functions">QApplication</a></li>
<li><divclass="fn"></div>1 protected function inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#protected-functions">QCoreApplication</a></li>
<li><divclass="fn"></div>7 protected functions inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#protected-functions">QObject</a></li>
<li><divclass="fn"></div>2 protected variables inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#protected-variables">QObject</a></li>
</ul>
<aname="details"></a>
<hr/>
<h2>Detailed Description</h2>
<p>The QtSingleApplication class provides an API to detect and communicate with running instances of an application.</p>
<p>This class allows you to create applications where only one instance should be running at a time. I.e., if the user tries to launch another instance, the already running instance will be activated instead. Another usecase is a client-server system, where the first started instance will assume the role of server, and the later instances will act as clients of that server.</p>
<p>By default, the full path of the executable file is used to determine whether two processes are instances of the same application. You can also provide an explicit identifier string that will be compared instead.</p>
<p>The application should create the QtSingleApplication object early in the startup phase, and call <ahref="qtsingleapplication.html#isRunning">isRunning</a>() to find out if another instance of this application is already running. If <ahref="qtsingleapplication.html#isRunning">isRunning</a>() returns false, it means that no other instance is running, and this instance has assumed the role as the running instance. In this case, the application should continue with the initialization of the application user interface before entering the event loop with <ahref="http://qt.nokia.com/doc/4.6/qapplication.html#exec">exec</a>(), as normal.</p>
<p>The <ahref="qtsingleapplication.html#messageReceived">messageReceived</a>() signal will be emitted when the running application receives messages from another instance of the same application. When a message is received it might be helpful to the user to raise the application so that it becomes visible. To facilitate this, QtSingleApplication provides the <ahref="qtsingleapplication.html#setActivationWindow">setActivationWindow</a>() function and the <ahref="qtsingleapplication.html#activateWindow">activateWindow</a>() slot.</p>
<p>If <ahref="qtsingleapplication.html#isRunning">isRunning</a>() returns true, another instance is already running. It may be alerted to the fact that another instance has started by using the <ahref="qtsingleapplication.html#sendMessage">sendMessage</a>() function. Also data such as startup parameters (e.g. the name of the file the user wanted this new instance to open) can be passed to the running instance with this function. Then, the application should terminate (or enter client mode).</p>
<p>If <ahref="qtsingleapplication.html#isRunning">isRunning</a>() returns true, but <ahref="qtsingleapplication.html#sendMessage">sendMessage</a>() fails, that is an indication that the running instance is frozen.</p>
<p>Here's an example that shows how to convert an existing application to use QtSingleApplication. It is very simple and does not make use of all QtSingleApplication's functionality (see the examples for that).</p>
<pre><spanclass="comment"> // Original</span>
int main(int argc, char **argv)
{
QApplication app(argc, argv);
MyMainWidget mmw;
mmw.show();
return app.exec();
}
<spanclass="comment"> // Single instance</span>
int main(int argc, char **argv)
{
QtSingleApplication app(argc, argv);
if (app.isRunning())
return !app.sendMessage(someDataString);
MyMainWidget mmw;
app.setActivationWindow(&mmw);
mmw.show();
return app.exec();
}</pre>
<p>Once this QtSingleApplication instance is destroyed (normally when the process exits or crashes), when the user next attempts to run the application this instance will not, of course, be encountered. The next instance to call <ahref="qtsingleapplication.html#isRunning">isRunning</a>() or <ahref="qtsingleapplication.html#sendMessage">sendMessage</a>() will assume the role as the new running instance.</p>
<p>For console (non-GUI) applications, <ahref="qtsinglecoreapplication.html">QtSingleCoreApplication</a> may be used instead of this class, to avoid the dependency on the <ahref="http://qt.nokia.com/doc/4.6/qtgui.html">QtGui</a> library.</p>
<p>See also <ahref="qtsinglecoreapplication.html">QtSingleCoreApplication</a>.</p>
<p>Creates a <ahref="qtsingleapplication.html">QtSingleApplication</a> object. The application identifier will be <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#applicationFilePath">QCoreApplication::applicationFilePath</a>(). <i>argc</i>, <i>argv</i>, and <i>GUIenabled</i> are passed on to the QAppliation constructor.</p>
<p>If you are creating a console application (i.e. setting <i>GUIenabled</i> to false), you may consider using <ahref="qtsinglecoreapplication.html">QtSingleCoreApplication</a> instead.</p>
<h3class="fn"><aname="QtSingleApplication-2"></a>QtSingleApplication::QtSingleApplication ( const <ahref="http://qt.nokia.com/doc/4.6/qstring.html">QString</a>&<i>appId</i>, int &<i>argc</i>, char ** <i>argv</i> )</h3>
<p>Creates a <ahref="qtsingleapplication.html">QtSingleApplication</a> object with the application identifier <i>appId</i>. <i>argc</i> and <i>argv</i> are passed on to the QAppliation constructor.</p>
<h3class="fn"><aname="QtSingleApplication-3"></a>QtSingleApplication::QtSingleApplication ( int &<i>argc</i>, char ** <i>argv</i>, <ahref="http://qt.nokia.com/doc/4.6/qapplication.html#Type-enum">Type</a><i>type</i> )</h3>
<p>Creates a <ahref="qtsingleapplication.html">QtSingleApplication</a> object. The application identifier will be <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#applicationFilePath">QCoreApplication::applicationFilePath</a>(). <i>argc</i>, <i>argv</i>, and <i>type</i> are passed on to the QAppliation constructor.</p>
<p>Special constructor for X11, ref. the documentation of <ahref="http://qt.nokia.com/doc/4.6/qapplication.html">QApplication</a>'s corresponding constructor. The application identifier will be <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#applicationFilePath">QCoreApplication::applicationFilePath</a>(). <i>dpy</i>, <i>visual</i>, and <i>cmap</i> are passed on to the <ahref="http://qt.nokia.com/doc/4.6/qapplication.html">QApplication</a> constructor.</p>
<p>Special constructor for X11, ref. the documentation of <ahref="http://qt.nokia.com/doc/4.6/qapplication.html">QApplication</a>'s corresponding constructor. The application identifier will be <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#applicationFilePath">QCoreApplication::applicationFilePath</a>(). <i>dpy</i>, <i>argc</i>, <i>argv</i>, <i>visual</i>, and <i>cmap</i> are passed on to the <ahref="http://qt.nokia.com/doc/4.6/qapplication.html">QApplication</a> constructor.</p>
<p>Special constructor for X11, ref. the documentation of <ahref="http://qt.nokia.com/doc/4.6/qapplication.html">QApplication</a>'s corresponding constructor. The application identifier will be <i>appId</i>. <i>dpy</i>, <i>argc</i>, <i>argv</i>, <i>visual</i>, and <i>cmap</i> are passed on to the <ahref="http://qt.nokia.com/doc/4.6/qapplication.html">QApplication</a> constructor.</p>
<p>De-minimizes, raises, and activates this application's activation window. This function does nothing if no activation window has been set.</p>
<p>This is a convenience function to show the user that this application instance has been activated when he has tried to start another instance.</p>
<p>This function should typically be called in response to the <ahref="qtsingleapplication.html#messageReceived">messageReceived</a>() signal. By default, that will happen automatically, if an activation window has been set.</p>
<p>See also <ahref="qtsingleapplication.html#setActivationWindow">setActivationWindow</a>(), <ahref="qtsingleapplication.html#messageReceived">messageReceived</a>(), and <ahref="qtsingleapplication-obsolete.html#initialize"class="obsolete">initialize</a>().</p>
<p>Returns the applications activation window if one has been set by calling <ahref="qtsingleapplication.html#setActivationWindow">setActivationWindow</a>(), otherwise returns 0.</p>
<p>See also <ahref="qtsingleapplication.html#setActivationWindow">setActivationWindow</a>().</p>
<p>Returns true if another instance of this application is running; otherwise false.</p>
<p>This function does not find instances of this application that are being run by a different user (on Windows: that are running in another session).</p>
<p>See also <ahref="qtsingleapplication.html#sendMessage">sendMessage</a>().</p>
<p>This signal is emitted when the current instance receives a <i>message</i> from another instance of this application.</p>
<p>See also <ahref="qtsingleapplication.html#sendMessage">sendMessage</a>(), <ahref="qtsingleapplication.html#setActivationWindow">setActivationWindow</a>(), and <ahref="qtsingleapplication.html#activateWindow">activateWindow</a>().</p>
<p>Tries to send the text <i>message</i> to the currently running instance. The <ahref="qtsingleapplication.html">QtSingleApplication</a> object in the running instance will emit the <ahref="qtsingleapplication.html#messageReceived">messageReceived</a>() signal when it receives the message.</p>
<p>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 <i>timeout</i> milliseconds, this function return false.</p>
<p>See also <ahref="qtsingleapplication.html#isRunning">isRunning</a>() and <ahref="qtsingleapplication.html#messageReceived">messageReceived</a>().</p>
<p>Sets the activation window of this application to <i>aw</i>. The activation window is the widget that will be activated by <ahref="qtsingleapplication.html#activateWindow">activateWindow</a>(). This is typically the application's main window.</p>
<p>If <i>activateOnMessage</i> is true (the default), the window will be activated automatically every time a message is received, just prior to the <ahref="qtsingleapplication.html#messageReceived">messageReceived</a>() signal being emitted.</p>
<p>See also <ahref="qtsingleapplication.html#activationWindow">activationWindow</a>(), <ahref="qtsingleapplication.html#activateWindow">activateWindow</a>(), and <ahref="qtsingleapplication.html#messageReceived">messageReceived</a>().</p>
<functionaccess="public"threadsafety="unspecified"status="commendable"name="QtSingleCoreApplication"fullname="QtSingleCoreApplication::QtSingleCoreApplication"href="qtsinglecoreapplication.html#QtSingleCoreApplication-2"location="qtsinglecoreapplication.h"virtual="non"meta="constructor"const="false"static="false"overload="true"overload-number="2"type=""signature="QtSingleCoreApplication(const QString & appId, int & argc, char ** argv)">
<functionaccess="public"threadsafety="unspecified"status="commendable"name="sendMessage"fullname="QtSingleCoreApplication::sendMessage"href="qtsinglecoreapplication.html#sendMessage"location="qtsinglecoreapplication.h"virtual="non"meta="slot"const="false"static="false"overload="false"type="bool"signature="sendMessage(const QString & message, int timeout)">
<functionaccess="public"threadsafety="unspecified"status="commendable"name="messageReceived"fullname="QtSingleCoreApplication::messageReceived"href="qtsinglecoreapplication.html#messageReceived"location="qtsinglecoreapplication.h"virtual="non"meta="signal"const="false"static="false"overload="false"type="void"signature="messageReceived(const QString & message)">
<functionaccess="public"threadsafety="unspecified"status="commendable"name="QtSingleApplication"fullname="QtSingleApplication::QtSingleApplication"href="qtsingleapplication.html#QtSingleApplication-2"location="qtsingleapplication.h"virtual="non"meta="constructor"const="false"static="false"overload="true"overload-number="2"type=""signature="QtSingleApplication(const QString & appId, int & argc, char ** argv)">
<functionaccess="public"threadsafety="unspecified"status="commendable"name="QtSingleApplication"fullname="QtSingleApplication::QtSingleApplication"href="qtsingleapplication.html#QtSingleApplication-3"location="qtsingleapplication.h"virtual="non"meta="constructor"const="false"static="false"overload="true"overload-number="3"type=""signature="QtSingleApplication(int & argc, char ** argv, Type type)">
<functionaccess="public"threadsafety="unspecified"status="commendable"name="sendMessage"fullname="QtSingleApplication::sendMessage"href="qtsingleapplication.html#sendMessage"location="qtsingleapplication.h"virtual="non"meta="slot"const="false"static="false"overload="false"type="bool"signature="sendMessage(const QString & message, int timeout)">
<functionaccess="public"threadsafety="unspecified"status="commendable"name="messageReceived"fullname="QtSingleApplication::messageReceived"href="qtsingleapplication.html#messageReceived"location="qtsingleapplication.h"virtual="non"meta="signal"const="false"static="false"overload="false"type="void"signature="messageReceived(const QString & message)">
<p>This example shows how to use the single-application functionality in a console application. It does not require the <tt>QtGui</tt> library at all.</p>
<p>The only differences from the GUI application usage demonstrated in the other examples are:</p>
<p>1) The <tt>.pro</tt> file should include <tt>qtsinglecoreapplication.pri</tt> instead of <tt>qtsingleapplication.pri</tt></p>
<p>2) The class name is <tt>QtSingleCoreApplication</tt> instead of <tt>QtSingleApplication</tt>.</p>
<p>3) No calls are made regarding window activation, for obvious reasons.</p>
<li><divclass="fn"><b><ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#processEvents-2">processEvents</a></b> ( QFlags<QEventLoop::ProcessEventsFlag>, int )</div></li>
<li><divbar="2"class="fn"></div>4 public functions inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#public-functions">QCoreApplication</a></li>
<li><divbar="2"class="fn"></div>29 public functions inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#public-functions">QObject</a></li>
<li><divbar="2"class="fn"></div>1 public slot inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#public-slots">QCoreApplication</a></li>
<li><divbar="2"class="fn"></div>1 public slot inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#public-slots">QObject</a></li>
<li><divbar="2"class="fn"></div>1 signal inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#signals">QCoreApplication</a></li>
<li><divbar="2"class="fn"></div>1 signal inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#signals">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><divclass="fn"></div>4 properties inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#properties">QCoreApplication</a></li>
<li><divclass="fn"></div>1 property inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#properties">QObject</a></li>
<li><divclass="fn"></div>1 public type inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#public-variables">QObject</a></li>
<li><divclass="fn"></div>38 static public members inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#static-public-members">QCoreApplication</a></li>
<li><divclass="fn"></div>4 static public members inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#static-public-members">QObject</a></li>
<li><divclass="fn"></div>1 protected function inherited from <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#protected-functions">QCoreApplication</a></li>
<li><divclass="fn"></div>7 protected functions inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#protected-functions">QObject</a></li>
<li><divclass="fn"></div>2 protected variables inherited from <ahref="http://qt.nokia.com/doc/4.6/qobject.html#protected-variables">QObject</a></li>
</ul>
<aname="details"></a>
<hr/>
<h2>Detailed Description</h2>
<p>A variant of the <ahref="qtsingleapplication.html">QtSingleApplication</a> class for non-GUI applications.</p>
<p>This class is a variant of <ahref="qtsingleapplication.html">QtSingleApplication</a> suited for use in console (non-GUI) applications. It is an extension of <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html">QCoreApplication</a> (instead of <ahref="http://qt.nokia.com/doc/4.6/qapplication.html">QApplication</a>). It does not require the <ahref="http://qt.nokia.com/doc/4.6/qtgui.html">QtGui</a> library.</p>
<p>The API and usage is identical to <ahref="qtsingleapplication.html">QtSingleApplication</a>, except that functions relating to the "activation window" are not present, for obvious reasons. Please refer to the <ahref="qtsingleapplication.html">QtSingleApplication</a> documentation for explanation of the usage.</p>
<p>A QtSingleCoreApplication instance can communicate to a <ahref="qtsingleapplication.html">QtSingleApplication</a> instance if they share the same application id. Hence, this class can be used to create a light-weight command-line tool that sends commands to a GUI application.</p>
<p>See also <ahref="qtsingleapplication.html">QtSingleApplication</a>.</p>
<hr/>
<h2>Member Function Documentation</h2>
<h3class="fn"><aname="QtSingleCoreApplication"></a>QtSingleCoreApplication::QtSingleCoreApplication ( int &<i>argc</i>, char ** <i>argv</i> )</h3>
<p>Creates a <ahref="qtsinglecoreapplication.html">QtSingleCoreApplication</a> object. The application identifier will be <ahref="http://qt.nokia.com/doc/4.6/qcoreapplication.html#applicationFilePath">QCoreApplication::applicationFilePath</a>(). <i>argc</i> and <i>argv</i> are passed on to the QCoreAppliation constructor.</p>
<h3class="fn"><aname="QtSingleCoreApplication-2"></a>QtSingleCoreApplication::QtSingleCoreApplication ( const <ahref="http://qt.nokia.com/doc/4.6/qstring.html">QString</a>&<i>appId</i>, int &<i>argc</i>, char ** <i>argv</i> )</h3>
<p>Creates a <ahref="qtsinglecoreapplication.html">QtSingleCoreApplication</a> object with the application identifier <i>appId</i>. <i>argc</i> and <i>argv</i> are passed on to the QCoreAppliation constructor.</p>
<p>Returns true if another instance of this application is running; otherwise false.</p>
<p>This function does not find instances of this application that are being run by a different user (on Windows: that are running in another session).</p>
<p>See also <ahref="qtsinglecoreapplication.html#sendMessage">sendMessage</a>().</p>
<p>Tries to send the text <i>message</i> to the currently running instance. The <ahref="qtsinglecoreapplication.html">QtSingleCoreApplication</a> object in the running instance will emit the <ahref="qtsinglecoreapplication.html#messageReceived">messageReceived</a>() signal when it receives the message.</p>
<p>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 <i>timeout</i> milliseconds, this function return false.</p>
<p>See also <ahref="qtsinglecoreapplication.html#isRunning">isRunning</a>() and <ahref="qtsinglecoreapplication.html#messageReceived">messageReceived</a>().</p>