qwindows.dll, Qt5Gui.dll, Qt5Core.dll not unloaded anymore, a Qt bug?
-
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, somehow. Is that a Qt issue that is still to be fixed?
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).
-
Qt5Gui.dll, Qt5Core.dll, and qwindows.dll these three dll are required for the Qt application to run.
When you say that you are unloading your dll, does it mean that you don't run the qt UI any more ? When you unload the library what else is running your process ? Is it just a C++ app or some thing else ?
-
@dheerendra Indeed, we have a rather large MFC based application (executable), with one of its GUI components (a dialog window) being developed using Qt. We implemented this GUI component of ours in a DLL, doing something like this:
extern "C" __declspec(dllexport) void MyDllExportFunc() { int argCount = 0; const QApplication qtApplication(argCount, nullptr); QMainWindow mainWindow; mainWindow.show(); QApplication::exec(); }
Note that this approach worked fine with Qt 4. Once we upgraded to Qt 5, we got this problem that Qt DLL's don't get unloaded anymore when our own DLL is unloaded.
-
Ok. Not sure about the issue persistence in Qt 5.0. My guess is that it is deliberately kept loaded for reasons not known to me. How about unloading them explicitly ? I'm sure these dlls are not loaded explicitly. Just to handle our issue , this may work.
-
@dheerendra said:
My guess is that it is deliberately kept loaded for reasons not known to me. How about unloading them explicitly ? I'm sure these dlls are not loaded explicitly. Just to handle our issue , this may work.
We did implement such a workaround, and it did handle the issue for quite some time, actually. It used to be sufficient to only unload qwindows.dll explicitly (calling FreeLibrary on its HMODULE). The other Qt DLL's would then automatically unload as well. This worked fine on Windows 7.
However, now that we're running our executable on Windows 10, the order in which Qt DLL's are loaded (automatically) appears changed, and explicitly unloading qwindows.dll sometimes appears to trigger an access violation within Qt5Core, when debugging in Visual Studio (VS2015). So we feel that a more fundamental fix would be appropriate.
-
@Niels-Dekker If I understand you right this issue only occur on Windows 10?
-
@jsulm said:
If I understand you right this issue only occur on Windows 10?
The original issue occurred on both Windows 7 and Windows 10: qwindows.dll, Qt5Gui.dll, and Qt5Core.dll were not unloaded when our Qt based DLL was unloaded. The workaround of explicitly unloading qwindows.dll within our Qt based DLL triggers access violations when debugging on Windows 10. We did not see those access violations on Windows 7.
-
Here is the code of my test example application ("MyQWindowsTestExe.exe"), which loads "MyDllExportFunc" from my Qt based DLL, "MyQWindowsTestDll.dll":
#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; }
And below here is what it loads and unloads, within the VS2015 debugger, running on Win10. You see, Qt5Widgets.dll and MyQWindowsTestDll.dll get unloaded, but qwindows.dll, Qt5Gui.dll, and Qt5Core.dll do not!
'MyQWindowsTestExe.exe' (Win32): Loaded 'F:\Q\Bin\vc14-64\MyQWindowsTest\MyQWindowsTestExe\Release\MyQWindowsTestExe.exe'. Module was built without symbols.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\sysfer.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbase.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'F:\Q\Bin\vc14-64\MyQWindowsTest\MyQWindowsTestDll\Release\MyQWindowsTestDll.dll'. Module was built without symbols.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Qt\Qt5.8.0\5.8\msvc2015_64\bin\Qt5Widgets.dll'. Module was built without symbols.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\gdi32full.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\win32u.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\cfgmgr32.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\windows.storage.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\combase.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\bcryptprimitives.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\powrprof.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\shlwapi.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\SHCore.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\profapi.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Qt\Qt5.8.0\5.8\msvc2015_64\bin\Qt5Gui.dll'. Module was built without symbols.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Qt\Qt5.8.0\5.8\msvc2015_64\bin\Qt5Core.dll'. Module was built without symbols.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\ws2_32.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\uxtheme.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\dwmapi.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\mpr.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\winmm.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\winmmbase.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\cryptbase.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Qt\Qt5.8.0\5.8\msvc2015_64\plugins\platforms\qwindows.dll'. Module was built without symbols.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\msvcp_win.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\msctf.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\clbcatq.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\DataExchange.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\d3d11.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\dcomp.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\dxgi.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\twinapi.appcore.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Loaded 'C:\Windows\System32\bcrypt.dll'. Cannot find or open the PDB file.
'MyQWindowsTestExe.exe' (Win32): Unloaded 'C:\Windows\System32\dxgi.dll'
'MyQWindowsTestExe.exe' (Win32): Unloaded 'C:\Windows\System32\d3d11.dll'
'MyQWindowsTestExe.exe' (Win32): Unloaded 'C:\Windows\System32\dcomp.dll'
'MyQWindowsTestExe.exe' (Win32): Unloaded 'C:\Windows\System32\twinapi.appcore.dll'
'MyQWindowsTestExe.exe' (Win32): Unloaded 'C:\Windows\System32\DataExchange.dll'
'MyQWindowsTestExe.exe' (Win32): Unloaded 'C:\Qt\Qt5.8.0\5.8\msvc2015_64\bin\Qt5Widgets.dll'
'MyQWindowsTestExe.exe' (Win32): Unloaded 'F:\Q\Bin\vc14-64\MyQWindowsTest\MyQWindowsTestDll\Release\MyQWindowsTestDll.dll' -
So... shall I submit a bug report on this issue?
-
Please have a look at the bug report I just submitted on this issue: https://bugreports.qt.io/browse/QTBUG-61059