Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. qwindows.dll, Qt5Gui.dll, Qt5Core.dll not unloaded anymore, a Qt bug?

qwindows.dll, Qt5Gui.dll, Qt5Core.dll not unloaded anymore, a Qt bug?

Scheduled Pinned Locked Moved Unsolved General and Desktop
windowsdllqt5loadlibrarybug
10 Posts 3 Posters 7.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Niels Dekker
    wrote on 23 May 2017, 09:50 last edited by
    #1

    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).

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 23 May 2017, 09:52 last edited by
      #2

      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
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      N 1 Reply Last reply 23 May 2017, 10:08
      1
      • D dheerendra
        23 May 2017, 09:52

        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 ?

        N Offline
        N Offline
        Niels Dekker
        wrote on 23 May 2017, 10:08 last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dheerendra
          Qt Champions 2022
          wrote on 23 May 2017, 10:23 last edited by
          #4

          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
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          N 1 Reply Last reply 23 May 2017, 10:51
          2
          • D dheerendra
            23 May 2017, 10:23

            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.

            N Offline
            N Offline
            Niels Dekker
            wrote on 23 May 2017, 10:51 last edited by
            #5

            @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.

            J 1 Reply Last reply 23 May 2017, 11:47
            0
            • N Niels Dekker
              23 May 2017, 10:51

              @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.

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 23 May 2017, 11:47 last edited by
              #6

              @Niels-Dekker If I understand you right this issue only occur on Windows 10?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              N 1 Reply Last reply 23 May 2017, 13:07
              0
              • J jsulm
                23 May 2017, 11:47

                @Niels-Dekker If I understand you right this issue only occur on Windows 10?

                N Offline
                N Offline
                Niels Dekker
                wrote on 23 May 2017, 13:07 last edited by
                #7

                @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.

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  Niels Dekker
                  wrote on 23 May 2017, 13:23 last edited by
                  #8

                  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'

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    Niels Dekker
                    wrote on 24 May 2017, 13:47 last edited by
                    #9

                    So... shall I submit a bug report on this issue?

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      Niels Dekker
                      wrote on 26 May 2017, 13:17 last edited by
                      #10

                      Please have a look at the bug report I just submitted on this issue: https://bugreports.qt.io/browse/QTBUG-61059

                      1 Reply Last reply
                      0

                      1/10

                      23 May 2017, 09:50

                      • Login

                      • Login or register to search.
                      1 out of 10
                      • First post
                        1/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved