Qt6 for Windows environment construction (MinGW)

Author: One trip, two or three miles
Personal WeChat ID: iwaleon
WeChat public account: Efficient programmer

In order to start developing with Qt, you need to set up a suitable development environment. Since our tutorial “QML in Detail” is based on Qt6, and so far, the latest version of Qt6 is Qt6.5, so we will take this version as an example to introduce in detail the development environment setup under Windows.

Installation reference

There are many ways to install Qt. You can choose online installation or offline installation, or you can compile the source code yourself. The official recommendation is that we choose to install online. The advantage of this is that it facilitates subsequent version changes (through the Qt Maintenance Tool).

As for the Online Installer, it is actually a download installation program and does not come with Qt components and modules. When we log in to the account, it will obtain the license associated with the account from the server and list the corresponding components and modules according to the license. Once we select it, it will be downloaded and installed in real time from the server, which ensures that the components and modules obtained are always up to date and suitable for the current platform.

The offline installer is a larger compressed package that contains all Qt modules and components related to the current platform (the size is usually much larger than the online installer), and can be installed in a non-network environment. However, due to official policy changes, starting from Qt 5.15, the offline installer is no longer provided.

Due to The Qt Company offering changes, open source offline installers are not available any more since Qt 5.15.
For more details, see: Qt offering changes 2020

In other words, to use the offline installer, you must either choose a version prior to 5.15 or become a commercial user.

For the download address of Qt, you can refer to the following link:

  • Qt download address: https://download.qt.io/
  • Online installer: https://download.qt.io/archive/online_installers/
  • Offline installer: https://www.qt.io/offline-installers

In addition, it is also recommended to understand some key knowledge of Qt:

  • Qt version history: https://en.wikipedia.org/wiki/Qt_version_history
  • Qt module: https://doc.qt.io/qt.html
  • Qt Licensing: https://www.qt.io/licensing/

Important note: Qt provides two license agreements – open source license and commercial license. If it is for personal study (not used as a commercial path), it does not have much impact; but if it is used within the company, it is best to use it with Communicate with the department manager and legal team to ensure that the agreement is followed and no violations occur.

Download the installer

Open the online installer, select the 4.6 installation package and download it:

Configure mirror source

If you directly use the online installer to install Qt, the speed will usually be very slow, because the default connection is to a foreign Qt server, and we are in China, and the network delay is high, resulting in slower download speeds.

In order to speed up the download of the Qt online installer, it is recommended to configure and use domestic mirror sources, for example:

  • Alibaba Cloud open source mirror station: https://mirrors.aliyun.com/qt/
  • Tsinghua University open source mirror site: https://mirrors.tuna.tsinghua.edu.cn/qt/
  • Shanghai Jiao Tong University open source mirror site: https://mirrors.sjtug.sjtu.edu.cn/qt/

Just open Powershell and execute the following command:

.\qt-unified-windows-x64-4.6.0-online.exe –mirror https://mirrors.tuna.tsinghua.edu.cn/qt/

Or open the Qt online installer and configure the Repository repository (Name and URL) in the settings.

In this way, the online installer will download the required components from the configured mirror source and let the speed take off.

Online installation

Run the downloaded Qt online installer and follow the installation wizard’s prompts to install.

  1. Log in

Log in to your Qt account. If you don’t have one, click “Register” on the interface to create one.

  1. Open source obligations

If it is for personal use, check the box at the bottom; if it is for a company, you need to fill in the company name.

It is recommended to read the agreement here carefully and follow it in subsequent use, otherwise it is easy to receive a lawyer’s letter.

  1. welcome

Welcome to Qt, just click “Next”.

  1. Contribute to Qt

The first is “Send statistics to help Qt improve” and the second is “Disable sending”.

I chose prohibition because I don’t know what exactly is being counted? What business modules are used? Or what sensitive information was collected? still …

  1. installation manual

Select the installation path according to your personal habits (it cannot contain special characters such as Chinese and spaces), and select “Customized installation”.

  1. Select components

These components are divided into two parts: one part is located under “Qt 6.5.2”, which mainly contains Qt development libraries and source code; the other part is located under “Developer and Designer Tools”, which mainly contains IDE (Qt Creator) and other tools , helps us improve development efficiency.

Component Description
WebAssembly Binary format for running applications in the browser, especially if you want to use Qt to develop Web applications It is deployed using WebAssembly, it is recommended to check it.
MSVC 2019 64-bit Applicable to MSVC (full name: Microsoft Visual C + + ) Qt development library of the compiler. If you want to use MSVC to build and run Qt programs, it is recommended to check it.
MinGW 11.2.0 64-bit Applicable to MinGW (full name: Minimalist GNU for Windows) compiler’s Qt development library. If you want to use MinGW to build and run Qt programs, it is recommended to check it.
Android Qt library developed for Android. If you want to adapt to Android, It is recommended to check this box.
Sources Qt source code, if you want to study the source code, it is recommended to check it.
Additional Libraries Some additional modules, most of which are recommended to be installed (do not take up much space ). Among them, Technology Preview in brackets after the module indicates a technology preview, indicating that the module is still under development (unofficial version module); while Deprecated refers to an abandoned old module (compatible with old code) and is generally not used.
Qt Creator 11.0.2 IDE, I will rely on it to write code later. required.
CMake A very popular open source cross-platform build tool with a design concept similar to QMake , but there are some differences in implementation and usage. Since the Qt6 tool chain has been gradually migrated from QMake to CMake, it is recommended to check this box.

  1. agreement

You have to accept it to continue the installation, so what’s there to say? Just check “Agree”.

  1. Start menu shortcut

The default is enough, just click “Next”.

  1. Ready to install

Here we will be prompted for the disk space that will be occupied during installation. If the disk size is not enough, you can click “Previous” to adjust it.

  1. Installing

The installation begins, please wait a moment.

  1. completed

The installation is complete here, click “Finish” to exit the Qt wizard.

Environmental testing

In order to test whether the Qt environment is successfully established, you can create a simple application, compile and run it.

Open Qt Creator, enter “Welcome” mode, click “Create Project” (or select “Create Project” in the “File” menu). Select “Qt Quick Application” in the pop-up dialog box, and then follow the wizard to complete the creation of the new project.

After the new project is created, a simple sample code will be generated:

import QtQuick
import QtQuick.Window

Window {<!-- -->
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
}

Click the “Run” button on the toolbar (or use the shortcut “Ctrl + R”) to compile and run the application. The effect is as follows:

Congratulations, this means that the Qt6 development environment has been successfully established. Let us officially enter the development journey together.

Little easter egg:

What did you discover after reading the article?

  • Qt5.15 will no longer provide an offline installer (strengthening the business agreement from now on)
  • An account is required to log in (collect user information)
  • Check and install components (record installation behavior and component usage)
  • Sending statistics helps Qt improve (what components are used for statistics?)
  • Strong emphasis on open source protocols (either contribute or pay)

Now you understand why you need to install it online, right? Personal information (account, company, component usage) can be better collected to analyze whether you have violated the license agreement.

Therefore, it is very important to follow the agreement. If you do not follow it, you will receive a letter from a lawyer. Of course, you are very likely to receive it even if you follow it. If you don’t believe it, ask your friends around you O(∩_∩)O haha~.