Qt6 for Windows environment construction (Visual Studio)

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

In Windows, if you want to develop Qt applications, you have several options:

We have introduced the first two methods before, mainly using Qt Creator as the IDE, and developing Qt with different compilers. Now it's time to introduce the third way, using Visual Studio as the IDE to develop Qt.

Qt Creator or Visual Studio

People often ask: Which IDE should I use when writing Qt programs - Qt Creator or Visual Studio?

  • Qt Creator
    is an IDE specially designed for Qt development. It is cross-platform, lightweight, intuitive and easy to use, and is tightly integrated with the Qt framework in terms of functions and workflow. It provides many useful functions, such as code editor, Designer designer, sample tutorials, etc.; in addition, it also has very useful auto-completion and code navigation functions, so that we can write Qt code more efficiently.

  • Visual Studio
    is a powerful and widely used IDE that supports many programming languages. It provides a wealth of functions and tools, including code editors, debuggers, performance analyzers, etc.; at the same time, it also supports many third-party plug-ins and extensions, such as distributed compilation tools IncrediBuild, static code inspection tools, and Qt Visual Studio Tools plugins etc.

In conclusion, both IDEs can be used for Qt development. If you want to be cross-platform and take advantage of the features of the Qt framework, it is recommended to choose Qt Creator; if you are used to using Visual Studio, and the project needs to be integrated with other non-Qt related codes, it is recommended to choose Visual Studio.

Download Visual Studio

For the download of Visual Studio, you can refer to the following address:

There are three versions of Visual Studio, Community Community Edition (free), Professional Professional Edition (paid), Enterprise Enterprise Edition (more expensive). Since we are using it personally, it is enough to choose the Community Community Edition (Because it's free).

When downloading Qt6.5, since we selected "MSVC 2019 64-bit", it is recommended to download the corresponding Visual Studio version (ie: 2019) to prevent compatibility problems later.

insert image description here

Install Visual Studio

After the Visual Studio download is complete, double-click Ready to Install.

At this time, it will check whether there are available updates or components that need to be downloaded and installed, including: specific workloads, components, modules, or other related content.

insert image description here

After a while, you will enter the component selection interface.

In the "Workload" interface, select "Desktop Development Using C++", and then select the language and installation location, and the installation can be done normally:

insert image description here

The installation process is long, please be patient!

insert image description here

install plugin

After the Visual Studio installation is complete, we can't use Qt immediately, and we need to install two additional plug-ins:

  • Qt Visual Studio Tools
    provides functions integrated with the Qt framework (such as project templates, Designer designers, etc.) to assist us in creating, building and debugging Qt projects, making Qt easier to use in Visual Studio.

  • Qt VS CMake Tools
    focuses on the integration with the CMake build system, enabling us to use CMake to build and manage Qt projects in Visual Studio.

Open Visual Studio, select [Extensions] -> [Manage Extensions] in the top menu bar, and then search for "Qt" in the opened "Manage Extensions" window, and these two plug-ins will appear in the search results. Download and install separately:

insert image description here

After installing these two plug-ins, you need to restart Visual Studio for the plug-ins to take effect.

Configure Qt

After opening Visual Studio, don't rush to create a project or open a project, because the Qt environment is not ready yet and needs to be configured.

Click "Continue without code" to enter the main interface for configuration.

insert image description here

As you can see, a warning appeared in Visual Studio, reminding us to configure the version of Qt.

Select [Extensions] -> [Qt VS Tools] -> [Qt Versions]:

insert image description here

A dialog box will pop up, add the qmake.exe path under the Qt MSVC installation directory in the "Path" column of the right table:

insert image description here

At this point, the configuration is basically complete.

environmental test

Now to create a test program, click [File] -> [New] -> [Project] in the menu bar in the upper left corner:

insert image description here

Drag the template list to the bottom, then you will see all Qt templates, select "Qt Quick Application" to create:

insert image description here

Fill in the project name, select the location where the project is saved, and click "Create":

insert image description here

In the pop-up wizard interface, the configuration to be included in the project will be listed, and the default recommended configuration can be used:

insert image description here

Next, the corresponding engineering code will be automatically generated.

Select [Debug] -> [Start Execution] on the menu bar (or the shortcut key Ctrl + F5) to run the code, the effect is as follows:

insert image description here

This means that the environment configuration is OK, and then you can happily write code with Visual Studio!

Guess you like

Origin blog.csdn.net/u011012932/article/details/132566368