- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个带有单个对话框窗口的 Qt 应用程序。主要看起来像这样:
QApplication a(argc, argv);
MyObject * myMobject = new QObject(&a);
MainWindow w;
w.show();
return a.exec();
MyObject
构造函数创建一个临时文件,析构函数将其删除。
当我通过关闭对话框正常关闭应用程序时,MyObject
析构函数按预期被调用,因为它是 QApplication
的子级,分配在堆栈中main()
.
但是,当用户 session 关闭(注销、关机...)时,文件不会被删除,这表明 MyObject
析构函数从未被调用。
这是什么原因?我虽然 Windows 在 session 关闭之前关闭了每个窗口,但看起来我的进程已终止。
在文档中,有 QCoreApplication::aboutToQuit()
信号。但是这个文档告诉 Qt 检测到关闭并退出事件循环,并在最后发出该信号。
如果情况确实如此,a.exec()
应该返回,就像窗口关闭时一样,QApplication
应该连同它的 child 一起销毁,调用MyObject
析构函数。换句话说,由于 myObject
是 a
的子项,因此不需要处理 aboutToQuit()
信号。
最佳答案
直接来自 QApplication 的文档:
We recommend that you connect clean-up code to the aboutToQuit() signal, instead of putting it in your application's main() function. This is because, on some platforms the QApplication::exec() call may not return. For example, on the Windows platform, when the user logs off, the system terminates the process after Qt closes all top-level windows. Hence, there is no guarantee that the application will have time to exit its event loop and execute code at the end of the main() function, after the QApplication::exec() call.
关于c++ - QApplication 子对象在系统关闭时不会被销毁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37755487/
我想念任何Qt如果我替换 QApplication::exec() 的功能使用标准的 Windows 消息循环实现?这应该澄清我的意思: 运行事件处理的常用“Qt”方式: int main(int a
何时在 Windows 上调用虚函数 QApplication::saveState 和 QApplication::commitData?它们是否被调用,或者 session 管理只是 UNIX 的
有两个qApplications A & B,它们可以在各自的主窗口中分别执行。 我想实现以下目标: 1) //Open Application B. //Inside App B's code
我正在尝试运行一个简单的 hello world 示例,并且已经需要一些时间来弄清楚要使用的内容现在我验证了包含路径,QApplication 实际上应该在那里,但它抛出了上述错误。为了清楚起见,我的
当我首先运行 python-pyside2 项目服务器时,它运行良好。 而且该站点也运行良好,但是如果我按 F5 btn 在浏览器中刷新。 站点显示错误页面 Runtime at/ import sy
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我正在将 Qt 桌面应用程序移植到 Linux(Ubuntu 19.10、64 位桌面、Qt 5.12.5、gcc 版本 9.2.1),并且在 QApplication 完成后发现一些意外的线程仍然处
这里引用 Qt 文档: For any GUI application using Qt, there is precisely one QApplication object 很明显。但我不知道为什
这里引用 Qt 文档: For any GUI application using Qt, there is precisely one QApplication object 很明显。但我不知道为什
我正在尝试将修改后的 qt 程序作为库运行。我需要它而不是阻止主执行。 所以我想做的是运行 QApplication 并开始执行主应用程序。我该如何实现? 我的第一个想法是在一个单独的线程中运行它。
我需要在单击按钮时重新启动我的应用程序,但我遇到了一些问题。我尝试了两种方法: 已尝试 this suggestion它确实重新启动了应用程序,但是我得到了每个小部件的 Gtk_IS_INVISIBL
我试图在不同的线程中创建 QApplication,但发现了 2 个主要问题: 1- 我无法与 GUI 交互 2- 一些警告: 警告:QApplication 不是在 main() 线程中创建的。 Q
是否可以在退出前一个实例后创建和使用新的 QApplication 实例? 最佳答案 是的,您可以在销毁前一个实例后创建一个新的 QApplication。我在 Windows 中使用 PyQt4 验
我是 PyQt4(和 QT)的新手,我遇到了一个问题, 我已经对 QApplication 进行了子类化(以具有对应用程序真正全局的全局数据和函数): class App(QApplication):
我正在 3Dsmax 2015 上做一些简单的 PySide。 这是我的错误: python.ExecuteFile "C:\Program Files\Autodesk\3ds Max 2015\s
我有一个带有单个对话框窗口的 Qt 应用程序。主要看起来像这样: QApplication a(argc, argv); MyObject * myMobject = new QObject(&a);
我有一个带有通知区域图标的应用程序,因此主窗口可能会忽略关闭事件。我正在尝试在应用程序退出时保存首选项和历史记录。我还想在应用程序运行时处理注销。虽然该应用程序是跨平台的,但它在 GNU/Linux
QApplication::QApplication ( int & argc, char ** argv ) Initializes the window system and constructs
我应该在哪里使用 except 块来记录 QApplication 的异常? 这似乎不起作用: app = QtGui.QApplication(sys.argv) MainWindow = Main
在基本的 C++ Qt Widgets 应用程序中,在堆栈上创建一个 QApplication 或直接在 main 函数中对其进行堆分配是可行的,但是在堆上调用一个函数-分配一个 QApplicati
我是一名优秀的程序员,十分优秀!