c++ - 卸载所有 qt dll

标签 c++ qt dll

我有一个包含 Qt GUI 的 dll,它由“服务器”应用程序启动,在 GUI 被终止(卸载)后继续运行。

一切正常,但如果我重新启动 GUI,一切都会崩溃。如果我只运行一次并列出加载的 dll,则永远不会卸载 Qt5Core、Qt5Gui 和 qwindows.dll。

我认为我需要卸载它们(我的 dll 在专用线程中创建一个 QApplication,正确销毁)

我在 Windows 7 上使用 msvc2010 编译器,没有日志(“一般保护错误”对我来说不是日志)。

是否有卸载所有 qt dll(Qtcore、QtGui、qwindows)的解决方案? (无需显式调用“FreeLibrary”函数)

最佳答案

我最近就同一问题向 Qt 公司创建了支持票,但收到的答复令人失望。有一个有意识的设计决定让 Qt 插件保持加载状态直到应用程序终止。因此,许多为非 Qt 主机应用程序设计的基于 Qt 的插件将不得不求助于脆弱的变通方法以确保正常运行。

当您卸载各种 Qt DLL 时,卸载顺序非常重要,因为许多 DLL 相互依赖。以下是我从 Qt 支持工程师那里收到的确切回复:

The plugins are deliberately not unloaded until the application terminates as there were problems in the past with unloading the plugins and therefore it was agreed that they should stay loaded for the lifetime of the application. You should unload the plugins first before unloading your own dll. The plugins can be unloaded in any order you want as they do not depend on each other, the main platform one - qwindows.dll - would be the main one which is handling the events and so on. So as long as the QApplication is no longer running an event loop then you should be able to safely unload this. As long as you unload the plugins before the Qt dlls then any clean up that the plugins do will be done with the still loaded Qt dlls and thus should not cause a crash then.

关于c++ - 卸载所有 qt dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36132995/

相关文章:

c++ - String Game,创建一个特定的循环? C++

c++ - 从派生类对象调用基类函数。在派生类构造函数中设置的基类数据成员

c++ - 来自主线程的信号未到达第二线程 Qt 5 中的插槽

c# - Delphi 5 可以使用 C# .Net 库吗?

c++ - 从 DLL 中的类调用方法而不暴露类

c++ - 本例中圆括号“()”重载是什么意思

c++ - Windows 上用于非 ASCII 文件名的 opencv imread()

c++ - 在 Qt 5 中重用现有的 QDirIterator

.net - Microsoft安全通报(2269637)对.NET编码的影响

c++ - 命令行测试程序 -> 只生产第一部分