Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.7.1, 5.8.0
-
None
-
Windows 7, Windows 10, Visual Studio
Description
We are developing a library for Windows, as a DLL, which is linked to Qt5 (5.7.1 or 5.8.0), and an executable that loads the DLL of us. Our DLL does QApplication::exec(). Our executable loads the DLL by Window API function LoadLibrary, and unloads the DLL by FreeLibrary. When it loads our DLL, Qt5Widgets.dll, Qt5Gui.dll, Qt5Core.dll, and qwindows.dll are also loaded "automatically". But when our executable unloads our DLL, qwindows.dll, Qt5Gui.dll, Qt5Core.dll are not unloaded anymore! Only Qt5Widgets.dll gets unloaded automatically.
It seems that Qt5Gui.dll, Qt5Core.dll, and qwindows.dll keep each other loaded. Below here, a minimal example:
// The code of "MyQWindowsTestDll.dll" #include <QApplication> #include <QMainWindow> extern "C" __declspec(dllexport) void MyDllExportFunc() { int argCount = 0; const QApplication qtApplication(argCount, nullptr); QMainWindow mainWindow; mainWindow.show(); QApplication::exec(); }
// The code of "MyQWindowsTestExe.exe" #include <Windows.h> int main() { HMODULE libraryHandle = LoadLibrary("MyQWindowsTestDll.dll"); FARPROC procAddress = GetProcAddress(libraryHandle, "MyDllExportFunc"); auto* dllFunc = reinterpret_cast<void(*)()>(procAddress); dllFunc(); FreeLibrary(libraryHandle); return 0; }
Relevant Visual Studio debugging output:
'MyQWindowsTestExe.exe' (Win32): Loaded 'F:\...\MyQWindowsTest\MyQWindowsTestExe\Release\MyQWindowsTestExe.exe'.
...
'MyQWindowsTestExe.exe' (Win32): Loaded 'F:\Q\Bin\vc14-64\MyQWindowsTest\MyQWindowsTestDll\Release\MyQWindowsTestDll.dll'.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Qt\Qt5.8.0\5.8\msvc2015_64\bin\Qt5Widgets.dll'.
...
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Qt\Qt5.8.0\5.8\msvc2015_64\bin\Qt5Gui.dll'.
...
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Qt\Qt5.8.0\5.8\msvc2015_64\bin\Qt5Core.dll'.
...
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Qt\Qt5.8.0\5.8\msvc2015_64\plugins\platforms\qwindows.dll'.
...
'MyQWindowsTestExe.exe' (Win32): Unloaded 'C:\Qt\Qt5.8.0\5.8\msvc2015_64\bin\Qt5Widgets.dll'
'MyQWindowsTestExe.exe' (Win32): Unloaded 'F:\...\MyQWindowsTest\MyQWindowsTestDll\Release\MyQWindowsTestDll.dll'
As you see above here, qwindows.dll, Qt5Gui.dll, Qt5Core.dll are loaded, but not unloaded.
The issue gets especially problematic when our executable tries to load our DLL a second time (when our library has been unloaded, but Qt5Core is still in memory).
This issue is being discussed at https://forum.qt.io/topic/79527/qwindows-dll-qt5gui-dll-qt5core-dll-not-unloaded-anymore-a-qt-bug