Graphical User Interface (GUI) - Qt¶
Below the details of what I have used to statically compile the Qt application. Before continuing two general remarks:
- Be careful with using copy-paste.
- The configuring, building, and installation each may take quite some time (up to several hours).
Unpack everything from the tarball into any folder:
tar -xvf qt-everywhere-opensource-src-5.9.0.tar.gz
./configure -static -release -silent -prefix ~/Qt/5.9.0_static -opensource -confirm-license -opengl -nomake examples -skip wayland -skip purchasing -skip serialbus -skip qtserialport -skip script -skip scxml -skip speech -qt-libpng -no-libjpeg -qt-zlib -qt-pcre -qt-harfbuzz -qt-freetype -c++std c++14
-c++std c++14may be omitted if the C++ version needed is not younger that
To speed-up one can increase the number of concurrent jobs. For example:
make -r -j 4.
The statically built Qt will be located at
~/Qt/5.9.0_static. To configure your Qt application to be built with static Qt version, you need to call
~/Qt/5.9.0_static/bin/qmakewhile you are in your project folder. Other steps are same as when you build with the regular (dynamic) Qt version.
If you want to plug static build of Qt into Qt Creator, just make a new toolchain with your default compiler (clang) and debugger, and with your static build of Qt (find QMake in the bin subdirectory of your static Qt build).
In principle static compilation of the GUI under Windows is a piece of cake. However, there are some things that have to be preprepared, and it can take quite some time if you are not pointed to the right direction.
I ended up using the blog-post of Dimitris Apeiro, which contained exactly what I needed. Following this post, here is a short summary on my set-up.
The following links may also be relevant:
- Qt notes on Windows deployment. Specifically notice that when static compilation is unsuccessful one can also use
windeployqt`. To do this:
- Open the
Qt 5.8 for Desktopcommand-prompt (this has the environment set correctly).
- Navigate to the
- Open the
Download the Qt framework from qt.io. I have used to following options:
- Qt 5.8
- MinGW 5.3.0 32 bit
- msvc 2015 32-bit (not used by me)
- msvc 2015 64-bit (not used by me)
- Sources (important, non-default)
- Qt Charts (default)
- Qt Data Visualization (default)
- Qt Purchasing (default)
- Qt Virtual Keyboard (default)
- Qt WebEngine (default)
- Qt Gamepad (TP) (default)
- Qt Network Auth (TP) (default)
- Qt Speech (default)
- Qt Script (Deprecated) (default)
- Qt Creator 4.2.1
- MinGW 5.3.0 (important, non-default)
After the installation is finished one should already be able to compile and run the GUI, however making use of dynamic linking of the Qt libraries. For static compilation, and thus stand-alone deployment, follow the steps below.
- Qt 5.8
Add the following lines to the end of the file
C:\Qt\5.5\Src\qtbase\mkspecs\win32-g++\qmake.conf(be sure to make a back-up first):
QMAKE_LFLAGS += -static -static-libgcc -no-exceptions QMAKE_CFLAGS_RELEASE -= -O2 QMAKE_CFLAGS_RELEASE += -Os -momit-leaf-frame-pointer DEFINES += QT_STATIC_BUILD
Dimitris Apeiro suggests the additional option
Open a Qt environment command prompt:
Qt 5.8 for Desktop (MinGW 5.3.0 32 bit).
Go to the Src folder:
cd .. cd Src
configure -static -platform win32-g++ -prefix "C:\Qt\Static" -debug-and-release -opensource -confirm-license -nomake examples -nomake tests -nomake tools -opengl desktop -no-angle -sql-sqlite -make libs -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype
Dimitris Apeiro adding the following line to C:QtSrcqtbasemkspecsfeaturesdefault_post.prf:
static:win32: QMAKE_LFLAGS += $$QMAKE_LFLAGS_STATIC_LIB
mingw32-make -k -j4 mingw32-make -k install
There might be errors, usually this is nothing to worry about.
Add the following line to the file
CONFIG += static
Add the newly created environment to Qt Creator, to facilitate easy usage.
- Give this a meaningful name (e.g.
Desktop Qt 5.8.0 MinGW Static 32 bit).
Qt Version, select the newly created
Qt 5.8.0 (Static).
- In the project, select this environment (and release), and compile. All done!
Update the version numbers as follows:
Upload the changes to GitHub and create a new release there (with the correct version number).
Upload the package to PyPi:
$ python3 setup.py bdist_wheel --universal $ twine upload dist/*