Qt6 for Windows environment construction (MinGW)

Author: Yiqu, Ersanli
Personal Wechat ID: iwaleon
Wechat Official Account: Efficient Programmer

In order to start developing with Qt, you need to set up a suitable development environment. Since our tutorial "Detailed QML" 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 the development environment under Windows in detail.

insert image description here

Installation reference

There are many ways to install Qt. You can choose to install it online or offline, or you can compile the source code yourself. The official suggestion is that we choose to install online. The advantage of this is that it is convenient for subsequent version replacement (via the Qt Maintenance Tool tool).

For the online installer (Online Installer), it is actually a download and installer, 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 selected, it is downloaded and installed live from the server, which ensures that the components and modules fetched are always up-to-date and suitable for the current platform.

The offline installer (Offline Installer) is a large 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 the change of the official policy, 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.
更多详见:Qt offering changes 2020

In other words, to use the offline installer, 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:

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

Important note: Qt provides two license agreements - open source agreement and commercial agreement, if it is a personal study (not used as a commercial approach), it will not have much impact; but if it is used in the company, it is best to communicate with the department manager and legal team , to ensure that the protocol is followed without violations.

download installer

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

insert image description here

Configure mirror source

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

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

Just open Powershell, 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 the speed will take off.

Install online

Run the downloaded Qt online installer, and follow the prompts of the installation wizard to install.

  1. Log in

Log in to the Qt account, if not, click "Register" on the interface to create it.

insert image description here

  1. open source obligation

If it is for personal use, check the bottom check box; if it is 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.

insert image description here

  1. welcome

Welcome to Qt, just click "Next".

insert image description here

  1. Contribute to Qt

The first is "Send statistics to help Qt improve", the second is "Disable sending".

I chose to ban, because I don't know what is counting? What business modules are used? Or is there any sensitive information collected? still…

insert image description here

  1. installation manual

Select the installation path according to personal habits (cannot contain special characters such as Chinese and spaces), and select "Custom Installation".

insert image description here

  1. select components

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

components describe
WebAssembly The binary format used to run the application in the browser. If you want to use Qt to develop web applications, especially use WebAssembly for deployment, it is recommended to check it.
MSVC 2019 64-bit Qt development library for MSVC (full name: Microsoft Visual C++) compiler, if you want to use MSVC to build and run Qt programs, it is recommended to check.
MinGW 11.2.0 64-bit Qt development library for MinGW (full name: Minimalist GNU for Windows) compiler. If you want to use MinGW to build and run Qt programs, it is recommended to check it.
Android For the Qt library developed for Android, if you want to adapt to Android, it is recommended to check it.
Sources Qt source code, if you want to study the source code, it is recommended to check it.
Additional Libraries Some add-on modules, mostly recommended (doesn't take up much space). Among them, the Technology Preview in the parentheses after the module indicates a technology preview, indicating that the module is still under development (informal version of the module); and Deprecated refers to an abandoned old module (compatible with old code), which is generally not used.
Qt Creator 11.0.2 IDE, you will rely on it to write code later, it is required.
CMake A very popular open source cross-platform build tool, the design concept is similar to QMake, but there are some differences in implementation and usage. Since the tool chain of Qt6 has been gradually migrated from QMake to CMake, it is recommended to check it.

insert image description here

insert image description here

  1. agreement

You must accept to continue the installation, so what is there to say? Just tick "Agree".

insert image description here

  1. start menu shortcut

The default is fine, just click "Next".

insert image description here

  1. ready to install

Here we will be prompted with the disk space that will be occupied during installation. If the disk size is not enough, you can click "Back" to adjust.

insert image description here

  1. Installing

The installation has started, wait a moment.

insert image description here

  1. completed

At this point, the installation is complete, click "Finish" to exit the Qt wizard.

insert image description here

environmental test

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

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

insert image description here

After the new project is created, a simple sample code is 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 key "Ctrl + R") to compile and run the application, the effect is as follows:

insert image description here

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

Easter eggs:

After reading the article, what did you find?

  • Qt5.15 no longer provides an offline installer (enhance the commercial agreement since then)
  • An account is required to log in (collect user information)
  • Check and install components (record installation behavior, usage of components)
  • Send statistics to help Qt improve (which components are used for statistics?)
  • Strong emphasis on open source agreements (either contribute or pay)

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

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

Guess you like

Origin blog.csdn.net/u011012932/article/details/132507400
Recommended