Saturday, 5 May 2018

Building QT Windows Apps

Introduction

QT has many different options for building Windows applications.  This note presents three of them, all using freely available software.

These options are:
  • MinGW32
    • advantages: Don't need to distribute the MSVC runtime, and the debugger is available and already configured.
  • MSVC2015 32 bit
    • advantages: Runs on 32-bit platforms, and has better accessibility support than MinGW32.
  • MSVC2015 64 bit
    • advantages: Can handle programs which have large memory usage, and has better accessibility support than MinGW32.

Install QT:

Download QT From:  https://www1.qt.io/download-open-source

Run the qt-unified-windows-installer, and:
  • Select QT x.x.x - Targetting msvc2015 32 & 64-bit if desired
  • Select QT x.x.x - Targetting MinGW 5.3.0 if desired
  • Select Installer 3.0
  • Select MinGW Libraries 5.3.0 if desired
  • Select WebEngine Libraries
  • Install into C:\QT

Install SSL (optional):

May not be required, at least for MinGW installations, due to files being found in the Qt tree.

Download OpenSSL From: https://slproweb.com/products/win32openSSL.html

Run the installer, and:
  • Install into C:\OpenSSL-Win32
  • or C:\OpenSSL-Win64

Install Git (optional):

Download Git from: https://git-scm.com/download/win

Run the installer and:

  • Select Large File Support
  • Associate .sh to be run with Bash
  • Use Git from Bash Prompt Only
  • Use OpenSSL
  • Checkout as-is, Commit Unix-style
  • Use MinTTY
  • Explorer integration is not necessary
  • Install into C:\Git

Install DotNet Framework Developer Pack:

This is only required if MSVC is to be used, and the currently installed version of .Net is below 4.5.1.

Download DotNet from: https://www.microsoft.com/net/download/windows

Run the installer and:

  • Install into default location

Install ICU (optional):

Has  been found to be necessary for Webkit applications.

Download ICU Binary for Windows (VS2015) from: http://site.icu-project.org/download
It is not clear if later versions than 60.2 support MSVC2015.

Run the installer and:
  • Instal into C:\ICU 


Install Microsoft Visual C++ (VC14) Build Tools 2015:

Uninstall previous build tools 2015 / VC14, and the 2015/VC14 runtime.

Download Visual Studio Build Tools 2015 from: https://www.visualstudio.com/vs/older-downloads/

Run the visualcppbuildtools_full installer and:
  • Select the latest SDK only if your code contains #include <windows.h>
  • Otherwise, don't select any SDKs or Options
  • Install into default location

Deployment:

Build your application, and then transfer the .exe file to your distribution folder.
At the command prompt, run 'windeployqt filename.exe' and all of the required Qt DLLs and support files will be transferred.

You will also need to transfer additional files, depending on which library or features you are using.  These will come from distributions such as MinGW, Microsoft Runtime, OpenSSL and ICU.

You can use the depends.exe dependency walker, which is bundled with numerous Microsoft development tools, and is also available from www.dependencywalker.com. Note that this tool does not detect DLLs which are opened with the dlopen method, as these are dynamically loaded.

Example MinGW 32-bit Libraries

These libraries can be found in the QT\Tools\mingw530_32\bin folder:
  • libgcc_s_dw2-1.dll
  • libstdc++-6.dll
  • libwinpthread-1.dll

Example OpenSSL Libraries

If you don't have any SSL networking code, you don't need these libraries.

These libraries are loaded with the dlopen method, and as such, will not be detected with the dependency walker.  They are also not installed with the windeployqt application - all of this is due to export licensing restrictions.

The symptom of a missing OpenSSL library looks like a network failure when trying to connect to an SSL server (e.g. https).

There are several different versions of these libraries (in the Qt distribution and the Git distribution), but the following has been found to work OK: QT\Tools\mingw530_32\opt\bin:
  • libeay32.dll
  • ssleay32.dll