qt - 未调用 QObject 析构函数

标签 qt memory-management destructor qobject

我的 Qt 应用程序中有两个 QObject 子类。这些类中的每一个都在堆栈上实例化了一个对象。以前,我的应用程序会干净地退出。然而,由于我已经更新到 Qt5.1.0,它们的析构函数没有被调用。启动调试器时,我两次收到以下警告。

the debug information found in "/usr/lib/debug//lib64/libfreebl3.so.debug" 
does not match "/lib64/libfreebl3.so" (CRC mismatch)

这是 Qt 中的错误还是我的代码中的错误?

最佳答案

参见QCoreApplication::exec的文档:

We recommend that you connect clean-up code to the aboutToQuit() signal, instead of putting it in your application's main() function because on some platforms the QCoreApplication::exec() call may not return. For example, on Windows 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 QCoreApplication::exec() call.

您使用不当。不能保证 exec 会在窗口关闭后终止。您应该使用 aboutToQuit 信号来停止其他线程。如果此信号也未发出,您需要在窗口关闭时显式调用 QApplication::quit()

关于qt - 未调用 QObject 析构函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17558861/

相关文章:

c++ - C++/Qt 中的 undefined reference 错误

javascript - QML/QT 无法将 C++ 中的 QList<QVariantMap> 转换为 javascript 中的对象数组

c++ - QFileSystemModel 中的文件是灰色的

c++ - 关于使用 QTabWidget 'addTab' 函数的快速问题

java - 任何人都可以建议 eclipse 工具来分析 java 内存使用情况

c++ - 在 C : How to properly write some sort of "delete/dispose" function? 中使用 C++ 类

c++ - 将参数传递给 "array-like"容器构造函数

学生结构中的 C 内存分配不起作用

c++ - 空析构函数做什么?

c++ - 获取错误没有匹配函数调用 ' '