After building qt from source, you may want to install the build results by running “mingw32-make install”. But wait a minute, you do not really need to install the generated binaries before using them. You now have the built qt libs/dlls. The headers are already included in qt src directory. You can certainly use them to build your app.
To use your customized building binaries of Qt, you need to create a new Kit in Qt Creator. Click Window/Options/Kits/Manual/Add to add a new manually configured kit. You need to specify the C/C++ compiler for the new kit such as the C:\Qt\Qt5.12.1\Tools\mingw730_64\bin\gcc.exe and C:\Qt\Qt5.12.1\Tools\mingw730_64\bin\g++.exe that are shipped by the Qt package when you installed Qt. You also need to specify the Qt version for the new kit. The Qt version is actually the qmake.exe you just built. I’ve been wondering why they do not simply call it “qmake” but “Qt version”. The reason is that here Qt Creator actually wants to get the include/lib directories of the Qt binaries that your app links to. Those directories are determined based on the relative path to the directory where qmake.exe you specified resides.
After configuring the new kit that uses your newly built qmake.exe, you can use the kit to build your app. You may encounter this error:
qt.qpa.plugin: Could not find the Qt platform plugin "windows" in "" This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
You need to add an environment variable QT_QPA_PLATFORM_PLUGIN_PATH=C:\build\qtbase\plugins\platforms in Run Environment for your app project. Now your app should be built successfully and run without problem in Qt Creator.
If you finally decide to install the built outcome to other place(so that you can use the build outcome without the need of Qt source), you can run “mingw32-make install” under some build directory such as :
cd c:\build\qtbase\src\gui mingw32-make install
This will install the gui module to C:\Qt\Qt-5.12.1. Specifically, it will install the following parts to that directory:
- install_dlltarget: copy Qt5Guid.dll/Qt5Gui.dll in C:\build\qtbase\bin to C:\Qt\Qt-5.12.1\bin.
- install_target: copy libQt5Gui.a/libQt5Guid.a in C:\build\qtbase\lib to C:\Qt\Qt-5.12.1\lib. Copy Qt5Gui.prl Qt5Guid.prl in C:\build\qtbase\lib to C:\Qt\Qt-5.12.1\lib after some modification. Copy C:\build\qtbase\lib\pkgconfig\Qt5Gui.pc to C:\Qt\Qt-5.12.1\lib\pkgconfig\Qt5Gui.pc after some modification.
- install_gen_headers: copy class include files such as C:\Qt\Qt5.12.1\5.12.1\Src\qtbase\include\QtGui\QAccessible to c:\Qt\Qt-5.12.1\include\QtGui\. Those class include files just contain one line that includes the traditional header file. For example, the file QAccessible only contains one line “#include “qaccessible.h”” . There are two versions of qaccessible.h, one is put alongside QAccessible in C:\Qt\Qt5.12.1\5.12.1\Src\qtbase\include\QtGui\ whose content is #include “../../src/gui/accessible/qaccessible.h”, i.e., refers to the real header; the other is the real header C:\Qt\Qt5.12.1\5.12.1\Src\qtbase\src\gui\accessible\qaccessible.h. Note that the first version of the header files is not copied to the installation directory.
- install_targ_headers: copy the real header files such as C:\Qt\Qt5.12.1\5.12.1\Src\qtbase\src\gui\accessible\qaccessible.h to C:\Qt\Qt-5.12.1\include\QtGui\qaccessible.h. Here, you can see an elegant design that allows you to use your custom build of Qt without installing them as talked before. The content of qaccessible.h in installation directory is different from the qaccessible.h in Src\qtbase\include\QtGui\. The former is the actually header content while the latter is just reference to the real header which guarantees you can use headers in Src\qtbase\include\QtGui without installing them.
- install_private_headers: copy private header files in C:\Qt\Qt5.12.1\5.12.1\Src\qtbase\src\gui such as C:\Qt\Qt5.12.1\5.12.1\Src\qtbase\src\gui\accessible\qaccessiblecache_p.h to C:\Qt\Qt-5.12.1\include\QtGui\5.12.1\QtGui\private\. You are not likely to include those private headers in your projects.
- install_qpa_headers: copy qpa related headers(both public and private) such as C:\Qt\Qt5.12.1\5.12.1\Src\qtbase\src\gui\accessible\qplatformaccessibility.h to C:\Qt\Qt-5.12.1\include\QtGui\5.12.1\QtGui\qpa\.
- install_pritarget: copy C:\build\qtbase\mkspecs\modules-inst\qt_lib_gui.pri to C:\Qt\Qt-5.12.1\mkspecs\modules\qt_lib_gui.pri. Note that C:\build\qtbase\mkspecs\modules\qt_lib_gui.pri is not copied here.
- install_privpritarget: copy C:\build\qtbase\mkspecs\modules-inst\qt_lib_gui_private.pri to C:\Qt\Qt-5.12.1\mkspecs\modules\qt_lib_gui_private.pri.
- install_cmake_qt5_module_file: copy Qt5GuiConfig.cmake, Qt5GuiConfigVersion.cmake, and Qt5GuiConfigExtras.cmake to C:\Qt\Qt-5.12.1\lib\cmake\Qt5Gui\
You may notice the installation/destination directory seems fixed as C:\Qt\Qt-5.12.1. Can I change the installation directory? You can set an environment variable INSTALL_ROOT before running “make install” like:
set INSTALL_ROOT=myprogrammingnotes.com mingw32-make install
Then, the built outcome will be copied to C:\myprogrammingnotes.com\Qt\Qt-5.12.1\. Unfortunately, you cannot use INSTALL_ROOT to alter the disk/drive in Windows system. It is fixed to C:. How to change the installation destination to drive other than C:? You should re-configure your Qt build.
cd c:\build\qtbase bin\qmake C:\Qt\Qt5.12.1\5.12.1\Src\qtbase\qtbase.pro -- -prefix d:\myprogrammingnotes.com cd C:\build\qtbase\src\gui qmake c:\Qt\Qt5.12.1\5.12.1\Src\qtbase\src\gui\gui.pro mingw32-make install
After re-configure, the qmake -prefix option will be written to qt.conf as:
[DevicePaths] Prefix=d:/myprogrammingnotes.com [Paths] Prefix=d:/myprogrammingnotes.com
When you re-run qmake against an .pro file, the Prefix property in qt.conf will be read by qmake and set the destination path of the copied files. Then “make install” will install the binaries/include files to d:\myprogrammingnotes.com. For example, the header files are now installed to d:\myprogrammingnotes.com\include\QtGui\.
You can also use qmake to re-configure your qt build in C:\build like
cd c:\build qtbase\bin\qmake C:\Qt\Qt5.12.1\5.12.1\Src\qt.pro -- -prefix d:\myprogrammingnotes.com
Or just use the configure script:
cd c:\build C:\Qt\Qt5.12.1\5.12.1\Src\configure.bat -prefix d:\myprogrammingnotes.com
You can see the prefix option not only changes the destination disk from C: to D:, but also changes the prefix from \Qt\Qt-5.12.1 to \myprogrammingnotes.com.