Qtsingleapplication using Notes

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.