Http://www.cnblogs.com/kevinzhwl/archive/2012/08/27/2658839.html
Qtsingleapplication, which is officially provided by QT, is used to enable only one instance to be started and to communicate to another instance at startup (dependent on the Qtnetwork module)
By default, the window is automatically activated when you receive a message
(a) Simple to use:
(1) Copy the Qtsingleapplication directory into the source directory of the project,
(2) Then modify the project's. Pro file and add the following line of code
Include (.. /QTSINGLEAPPLICATION/SRC/QTSINGLEAPPLICATION.PRI)
(3) Modify the Main.cpp file, add the header file
#include <QtSingleApplication>
And
Qtsingleapplication app (argc, argv);
if (app.isrunning ())
{
App.sendmessage ("Raise_window_noop");
return exit_success;
}
........
Qmainwindow W;
App.setactivationwindow (&W);
.......
(4) Complete
(ii) Improved use:
(1) Identification procedure
By default, Qtsingleapplication uses Qapplication::applicationfilepath as its own appid to identify different apps
If you want to be unaffected by the program's store path, you need to specify AppID. As follows
Qtsingleapplication app (qlatin1string ("my_app_id"), argc, argv);
So that even in a different directory of the program, can still be mutually exclusive
(2) Sending messages and activating Windows
Sending and receiving messages is a unique feature of qtsingleapplication, and qapplication is not.
By default, Qtsingleapplication receives any message after it has its own window window. If you do not want to activate the window, you can set it yourself and even reconnect the signal slot. As follows
App.setactivationwindow (&w,false);
Qobject::connect (&app, SIGNAL (messagereceived (const qstring&)), &w, SLOT (handlemessage (const QString &));
Qtsingleapplication using Notes