我如何在再次打开应用程序时显示应用程序Qt [英] How I show application when open application again Qt
本文介绍了我如何在再次打开应用程序时显示应用程序Qt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在,我有1个应用程序,但是我不想两次打开应用程序,因此我使用 QShareMemory
来检测两次打开的应用程序.我的问题是:当用户第二次打开应用程序时,如何在屏幕上显示当前应用程序?
Now, I have 1 application, but I don't want to open application twice, so I using QShareMemory
to detect application when open twice.
And my question is: how I show current application in screen when user open application the second ?
int main(int argc, char *argv[]) {
Application a(argc, argv);
/*Make sure only one instance of application can run on host system at a time*/
QSharedMemory sharedMemory;
sharedMemory.setKey ("Application");
if (!sharedMemory.create(1))
{
qDebug() << "123123Exit already a process running";
return 0;
}
/**/
return a.exec();
}
谢谢.
推荐答案
只需使用 QSingleApplication
类而不是 QApplication
: https://github.com/qtproject/qt-solutions/tree/master/qtsingleapplication
int main(int argc, char **argv)
{
QtSingleApplication app(argc, argv);
if (app.isRunning())
return 0;
MyMainWidget mmw;
app.setActivationWindow(&mmw);
mmw.show();
return app.exec();
}
它是Qt Solutions的一部分: https://github.com/qtproject/qt-solutions
It is part of Qt Solutions: https://github.com/qtproject/qt-solutions
这篇关于我如何在再次打开应用程序时显示应用程序Qt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文