QT example executables won't run, missing QT5Cored.dll

前端 未结 3 2088
[愿得一人]
[愿得一人] 2020-12-13 21:36

QT5Cored.dll is on my system @: C:\\Qt\\5.4\\mingw491_32\\bin folder

The Analogclock example and other projects will run in the IDE, but can Not be run from the crea

相关标签:
3条回答
  • 2020-12-13 22:15

    To run it outside of Qt Creator, you have two choices:

    1. Copy the missing DLLs to the directory where the executable resides. For example if analogclock.exe is in c:\examples, then copy C:\Qt\5.4\mingw491_32\bin\Qt5Cored.dll and other required DLLs to c:\examples. You may need to copy plugins files too.
    2. Add C:\Qt\5.4\mingw491_32\bin to the PATH environment variable.

    There are some ways to copy the missing DLLs:

    1. Use Windows Deployment Tool (windeployqt.exe) to copy required files

    1. Open Command Prompt in one of the following way:
      1. If you use MSVC as compiler, open the correct Visual Studio Command Prompt. For example for VS2013 32-bit, click Start -> Microsoft Visual Studio 2013 -> Visual Studio Tools -> VS2013 x86 Native Tools Command Prompt. This will open a Command Prompt with the VCINSTALLDIR environment variable correctly set. windeployqt.exe requires this environment variable to copy the correct Visual C++ redistributable executable.
      2. If you use MinGW, just open a Command Prompt.
    2. Add Qt binary path and optionally g++.exe path to PATH environment variable. If your executable is 32-bit, add the 32-bit Qt binary path, eg: c:\Qt\5.4\msvc2013\bin. If your executable is 64-bit, add the 64-bit Qt binary path, eg: c:\Qt\5.4\msvc2013_64\bin. windeployqt.exe will copy DLLs from this directory, so it is important that you don't set 32-bit Qt binary path for a 64-bit executable, vice versa. You need to add g++.exe path too if you use MinGW, windeployqt will copy lib*.dll from there.

      ; Example path for MSVC 32-bit
      PATH=c:\Qt\5.4\msvc2013\bin;%PATH%
      
      ; Example path for MinGW 32-bit, g++.exe is in C:\Qt\Tools\mingw491_32\bin
      PATH=C:\Qt\5.4\mingw491_32\bin;C:\Qt\Tools\mingw491_32\bin;%PATH%  
      
    3. Run windeployqt.exe with your executable file as argument. Eg:

      windeployqt.exe C:\Qt\Examples\Qt-5.4\widgets\richtext\build-calendar-Desktop_Qt_5_4_0_MSVC2013_32bit-Debug\debug\calendar.exe
      
    4. Check the output for error or warning. The following is an output without error and warning:

    enter image description here

    2. Manually copy the DLLs

    You must copy the correct DLLs (32-bit or 64-bit). Use a tool like Process Explorer to find the correct DLL paths:

    1. Run the application from Qt Creator / Visual Studio.
    2. Open Process Explorer.
    3. In Process Explorer
      1. Click the executable, for example calendar.exe
      2. Press Ctrl+D to show loaded DLLs in the lower panel. The equivalent menu is View -> Lower Panel View -> DLLs
      3. In the lower panel, click the Path column to sort by path.
    4. Copy the DLLs to the directory where the executable resides. For example in the following picture. The DLLs are from C:\Qt\5.4\msvc2013\bin.

    Process Explorer

    1. If your executable uses something like c:\Qt\5.4\msvc2013\plugins\platforms\qwindowsd.dll. It should be copied too. But copy from the platforms directory, not plugins. Let's say calendar.exe's full path is c:\examples\calendar.exe, then qwindowsd.dll should be copied to c:\examples\platforms\qwindows.dll, not c:\examples\plugins\platforms\qwindows.dll.
    2. You need to copy C++ runtime library too. If you are using mingw, you may need to copy libgcc_s_dw2-1.dll, libstdc++-6.dll. libwinpthread-1.dll etc too. Check in Process Explorer to be sure. If you are using MSVC, you need to deploy the runtime (Eg: msvcp120.dll, msvcr120.dll). At the end, your directory structure is something like this:

      c:\examples\calendar.exe
      c:\examples\Qt5Cored.dll
      c:\examples\Qt5Widgetsd.dll
      c:\examples\Qt5Guid.dll
      c:\examples\icudt53.dll
      c:\examples\icuin53.dll
      c:\examples\icuuc53.dll
      c:\examples\libgcc_s_dw2-1.dll   (if using mingw)
      c:\examples\libstdc++-6.dll      (if using mingw)
      c:\examples\libwinpthread-1.dll  (if using mingw)
      c:\examples\platforms\qwindowsd.dll
      
    0 讨论(0)
  • 2020-12-13 22:18

    The answer given by fxam is an in-depth, comprehensive one. I have tried the approaches provided and they work!

    Just add a comment that in case of MinGW64, one should run windeplyqt.exe in the directory of "C:\Qt\Qt5.13.1\5.13.1\mingw73_64\bin".

    DrumM's answer is the simplest solution. It has been mentioned as 1.2. in fxam's answer though.

    0 讨论(0)
  • 2020-12-13 22:20

    A simple solution for me was just adding the QTDIR C:\Qt\5.4\msvc2017_64\ to your Windows system variables.

    1. In Windows search, type 'env' and press "Edit the system environment variables"
    2. Press "Environment Variables" below
    3. In the System variables list, press "New..."
    4. Add QTDIR as variable name, with value the directory name of the compiler under the Qt directory: C:\Qt\5.4\mingw491_32 in your case
    0 讨论(0)
提交回复
热议问题