我如何在再次打开应用程序时显示应用程序Qt

编程入门 行业动态 更新时间:2024-10-28 08:26:17
本文介绍了我如何在再次打开应用程序时显示应用程序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

本文发布于:2023-11-27 04:57:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636695.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   如何在   Qt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!