How to build 64-bit MinGW Qt application on Windows (with Qt Creator)

Update 3/11/2019: Starting with Qt 5.12 the Qt Project officially supports MinGW-w64 in 64-bit mode. You can install it from the Qt installer or build it yourself from Qt's sources (they've ironed out issues that were preventing successful builds).

Prior update: I think that rubenvb's answer is now the best answer to this question: MSYS2 contains an up-to-date Qt built with MinGW-w64, which is what you'll need to build 64-bit Qt apps. I recommend using the Qt wiki link in rubenvb's answer for deployment; it's greatly improved.

Qt64-NG

I recommend installing your Qt build from the Qt64-NG project.

The project provides an up-to-date, x64 Qt build with MinGW-w64. The MinGW-w64 project's GCC compiler is also included in the installer versions (but not in the 7z). You'll want the same version of GCC in MinGW-w64 that was used to build Qt for building your own apps, so I'd recommend choosing the installer.

You will need to choose a build with the exception stack frame unwinding method you want. The question What is difference between sjlj vs dwarf vs seh? describes the differences between the types of exception handlers that are present in different builds of Qt. SJLJ was the only choice before GCC 4.8 was released, but later GCC versions support SEH. Either choice will work, though SEH is more efficient.

Post-install

After you install Qt, you could add the Qt/qt-ver/qt-ver/bin and Qt/qt-ver/mingw64/bin directories to your User or System Path variable in your Environment Variables, which will allow you to use MinGW-w64's GCC for building from your preferred build process. Qt Creator will auto-detect MinGW-w64 as an installed compiler after you do this.

If you would rather not add to your path, you can specify the compiler for the version you just set up with Qt Creator, manually. You will likely need to add the Qt version by selecting qmake.exe under Options > Build & Run. You'll also want to select gdb.exe as your debugger under the Build & Run > Debuggers tab. It will be located at Qt/qt-ver/qt-ver/mingw64/bin.

You can exchange the MinGW-w64 toolchain with other toolchains. To do this in Qt Creator you can create and swap between kits.

Deployment

You can use the Qt64-NG build for development and deployment. To deploy, you'll want to package the files your application will need to run with your application, so your end-user won't have to do any extra installation steps.

First, create a deployment folder (likely with your application name) and copy your application exe file to it. If you're using Qt Creator, you can find the path to your application exe either in the Projects tab on the side bar or in the application's .pro file if it is specified there.

There are two ways that you can copy the dll dependencies you'll need to run your application. You can either copy the needed files manually or you can use windeployqt, a program provided with your Qt installation that will automatically copy (most) needed dependencies for deployment to the application deploy folder you just created.

Copy files manually

Copy the following dll files from your Qt/qt-ver/qt-ver/bin and Qt/qt-ver/mingw64/bin folders to your application deploy folder. Some dll files will be located in both folders, and either location is acceptable for use:

icudt54.dll
icuin54.dll
icuuc54.dll
libgcc_s_sjlj.dll or libgcc_s_seh.dll (corresponds with chosen stack unwinding method)
libssp-0.dll
libstdc++-6.dll
libwinpthread-1.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Widgets.dll

You'll also need to include any Qt5*.dll files that correspond with Qt modules you are using in your project.

Next, you'll need to copy any plugin dll files that Qt requires. Qt will look for plugins by default at application deploy folder/plugins. You can find the plugin folders you will want to copy at Qt/qt-ver/qt-ver/plugins. The exception to this is the platforms folder, which it will try to find at your application deploy directory/platforms. The following directory structure indicates where to copy files for a minimal project. Copy any other needed plugins including the containing folder to your deployment/plugins folder.

/deploy

/platforms
/plugins
icudt54.dll
icuin54.dll
icuuc54.dll
app.exe
libgcc_s_seh-1.dll
libssp-0.dll
libstdc++-6.dll
libwinpthread-1.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Widgets.dll

/deploy/platforms

qwindows.dll

/deploy/plugins/imageformats

qjpeg.dll

Windeployqt

You can find windeployqt.exe in your Qt/qt-ver/qt-ver/bin folder. Windeployqt requires that your Qt/qt-ver/qt-ver/bin and mingw64/bin folder be in your User or System Path variable to work properly.

To use windeployqt, open a command window and change to your application deploy directory. The syntax for running it can be found at Qt Deployment. You'll probably want to run it as follows:

windeployqt.exe app.exe

Windeployqt (Qt 5.4.1) will copy your imageformats and iconengines plugin folders to your application deploy directory level instead of inside a plugins folder. This is the correct location, as it alters where Qt looks for these folders.

Troubleshooting

You can test to see if you have the correct files by running your application on a computer that doesn't have the Qt development library installed and in the path. If you get no errors on your application startup, you'll know that Qt found the dependencies it needed, and you can package your application for distribution.

If you are getting errors, refer to the Tripleboot deployment guide. You can also try using Process Explorer to see what dependencies your application attempts to load when it gives a dependency-missing error.

Packaging

Frequently applications are distributed with an archive and/or an installer. The Qt Installer Framework provides a convenient way to package your Qt application for distribution as an installer executable.


You can install MSYS2, which includes a package manager and prebuilt versions of load of packages including Qt which you can also use outside of the MSYS2 environment with e.g. Qt Creator (which is also in the repositories by the way).

Installation is easy:

  1. Download the installer from the web page.
  2. Open the MSYS2 command prompt and install Qt:

    pacman -Sy mingw-w64-{i686,x86_64}-qt5

  3. Qt's qmake is installed in <msys2>/mingw{64,32}/bin and accessible from the respective command prompts.

In the same way you can install hundreds of other libraries and tools you might need for your development.

As for the rest of application deployment, I refer you to the Qt project wiki page on Windows deployment.