我的 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/