Unified tutorial for dynamic and static compilation of Qt projects for C++

Environment installation

Requirements download

Requirements Links
Qt 5.7 dynamic compiler qt-opensource-windows-x86-msvc2015-5.7.1
Visual Studio 2015 vs2015.pro_chs.iso
Compiled Qt 5.7 static compiler qt5-x86-static-release.7z
MinGW mingw-w64-install.exe
Qt VS AddIn qt-vsaddin-msvc2015-2.4.3.vsix
Visual Studio Code https://code.visualstudio.com/Download

Installation order

  1. Install Qt 5.7 dynamic compiler
  2. Install Visual Studio 2015
  3. Install Qt VS AddIn
  4. Install MinGW
  5. Install Visual Studio Code

Environment configuration

Dependencies

  1. Open the project with VS2015, right click Project - Properties
  2. Configure the selection Release
  3. Open Configuration Properties - C/C++ - Code Generation - Runtime Library and select Multithreading (/MT)
  4. Open Configuration Properties - Linker - Input - Additional Dependencies and paste in the following long string of characters:
$(QTDIR)\lib\qtmain.lib;$(QTDIR)\lib\Qt5Widgets.lib;$(QTDIR)\plugins\platforms\qwindows.lib;winspool.lib;shlwapi.lib;rpcrt4.lib;$(QTDIR)\lib\Qt5PlatformSupport.lib;$(QTDIR)\plugins\imageformats\qdds.lib;$(QTDIR)\plugins\imageformats\qicns.lib;$(QTDIR)\plugins\imageformats\qico.lib;$(QTDIR)\plugins\imageformats\qtga.lib;$(QTDIR)\plugins\imageformats\qtiff.lib;$(QTDIR)\plugins\imageformats\qwbmp.lib;$(QTDIR)\plugins\imageformats\qwebp.lib;$(QTDIR)\lib\Qt5Gui.lib;comdlg32.lib;oleaut32.lib;imm32.lib;winmm.lib;glu32.lib;opengl32.lib;gdi32.lib;$(QTDIR)\lib\qtharfbuzzng.lib;$(QTDIR)\lib\Qt5Core.lib;kernel32.lib;user32.lib;shell32.lib;uuid.lib;ole32.lib;advapi32.lib;ws2_32.lib;mpr.lib

Qt configuration

  1. Complete the additional dependencies configuration from the previous step
  2. Unzip the compiled Qt static compiler qt5-x86-static-release
  3. Open the project with VS2015, click [Qt VS Tools] -> [Qt Options] -> [Add], select the Qt static compiler path unzipped just now and confirm
  4. Select qt5-x86-static-release in the [Default Qt/Win version] drop-down menu, click OK

Debug

  1. Right-click the project directory and open the project with VSCode
  2. Confirm that the includePath of c_cpp_properties.json in the project is correctly configured with the Qt 5.7 dynamic compiler path installed earlier, and the compilerPath is correctly configured with the environment variable path of MinGW
  3. Click Run - Start Debug (or press F5 directly on the keyboard to start Debug mode)

Release

  1. Open the project with VS2015
  2. Select Release mode x86
  3. Select Build - Rebuild Solution
  4. Take out the .exe file from Release in the project directory, which is the file for release
posted @ 2022-12-31 18:07  天才俱乐部  阅读(126)  评论(0)    收藏  举报