本文介绍了我如何在再次打开应用程序时显示应用程序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 : github/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的一部分: github/qtproject/qt-solutions
It is part of Qt Solutions: github/qtproject/qt-solutions
更多推荐
我如何在再次打开应用程序时显示应用程序Qt
发布评论