Use Qt to develop projects in VS

Please add a picture description


foreword

When using Qt, some people don't like the IDE (Qt creator) that comes with Qt itself very much. They want to develop Qt projects in the VS that they have been using. This article will explain a series of problems encountered in the process of VS connecting to Qt. question.

The content of each part is for the overall development environment , that is to say: issues such as version selection and configuration are decisions made after considering many aspects. For example, choosing the version of Qt not only considers the connection between VS and Qt, but also considers the use of MySQL database in Qt.

You can take a look at my previous blog QT failed to connect to the MySql database, compilation driver problem, the most detailed solution

Regarding how to use MySQL in VS, I will improve the notes and update this blog.

 

The blogger’s own collocation: VS2022 + Qt5.15.2 + MySQL8.0
 

Generally speaking, it is probably such a match:
​vs2015 matches probably Qt5.7, 5.9, 5.6, and
vs2017 matches probably Qt5.9~Qt5.14
vs2019/vs2022 matches probably Qt5.14~Qt6

 

1. Selection and installation of Qt and VS versions

(1) Selection and installation of Qt version

1. Version selection

Why did Qt5.15.2
 
choose this version:

(1) It is better to choose this version when connecting to the MySQL database in Qt. The specific reasons can be found in the QT installation attention part of the blog mentioned in my preface , taking into account the problems when using Qt to connect to the MySQL database

insert image description here
(2) It is not until QT5.15.2 that there is an editor for MSVC2019. Here, if some people consider using their new version of vs to develop QT programs in the future, it must be no problem to use the new msvc2019 compiler. If it is 2017, your vs If it is too new it may not be supported. This is also mentioned in the blog given in my preface

So can it be concluded that the high version VS must not support the low version Qt, I don't think so, but it is not recommended! Because a stable compilation environment is the first choice, as shown in the figure below, a new qt5.5 project was created with vs2022, and the msvc2010 compiler corresponding to qt5.5 was used and the compilation passed, but it needs to correspond to the windows sdk version and so on.

insert image description here
insert image description here

(3) Qt5.14 does not support vs2019, but only supports 2017. If you choose to install and use the MSVC2017 compilation environment in Qt5.14, if VS2019 is installed on the computer, it may not work. In the final analysis, the second point is the compatibility issue between the high version VS and the low version Qt

Note: Use the MSVC compiler in Qt (note that you use the MSVC compiler in Qt, not in VS): Qt needs to be manually configured to use the MSVC compiler alone, but if you download the complete VS first, You don’t have to. For specific manual configuration operations, please refer to the article
Qt Add MSVC2017 Compiler (2022 nanny-level tutorial, do not install complete VS)

 
Summary:
It is best to match the versions of the VS version of the MSVC compiler and the Qt version of the MSVC compiler. After all, a stable compilation environment is the first choice.

 

2. Qt installation

For specific installation steps, please refer to the QT5.15.2 online installation tutorial (detailed graphics)

Here is my own plug-in selection:
insert image description here
insert image description here
I saw other bloggers say: It is best to disconnect the network before installing Qt (the version before 5.14 can be installed offline, and it must be installed online after 5.15), otherwise it cannot be next, and account registration is required, which is very difficult trouble.
I haven't used this operation here, write it out for those who need it
 
 

(2) Selection and installation of VS version

1. Version selection

The version selection requirements of VS are relatively simple, and generally match the matching. You can look at the red font matching in the preface. The minimum requirement is that the VS version of the MSVC compiler is higher than the Qt version of the MSVC compiler, but I have not tried it. Or the old saying:

It is best to match the versions of the VS version of the MSVC compiler and the Qt version of the MSVC compiler. After all, a stable compilation environment is the first choice.

2. VS installation

For specific installation steps, please refer to the latest version of Visual Studio 2022 installation tutorial (detailed explanation with thousands of words and pictures), which will teach you how to install and run VS2022 step by step (+background image settings)

insert image description here
insert image description here
It is now a modular installation. Under normal circumstances, it is good to check the desktop development using C++ and the expansion development of Visual Studio , as shown in the figure above
 

2. The connection between VS and Qt

(1) Install the plug-in

Open VS2022, click Extension->Extension Management->Online->Search QT, as shown below, download the plug-in

insert image description here

(2) Qt path configuration

Operate as shown below:

insert image description here
insert image description here
insert image description here
Just add the msvc compiler path of your Qt, be careful not to include it in the bin layer. After completion, it is as follows:
insert image description here

(3) Test

To create a new project, there is a qt project template directly, the next step in order, the next step is enough:

insert image description here
After completion is as follows:

insert image description here
QtWidgetsApplication1.ui: UI interface, double-click to open, it will open in the QTDesigner tool, you can drag the plug-in to design the interface.
QtWidgetsApplication1.h: The header file of the main thread function, declare the name of the slot function, define the name of the UI variable of the main interface, and so on.
QtWidgetsApplication1.qrc: Resource file: where you can add software icons, etc.
main.cpp: Contains the entry of the program and the operations displayed on the interface.
QtWidgetsApplication1.cpp: The program file of the main thread. The functions of the main thread interface are implemented in this file.
 

(4) Precautions

1. If you are using Qt6

Because qt6 requires C++17, the vs project properties need to be changed in two places, as follows:

① Project right-click properties, c/c++, command line, paste /Zc:__cplusplus

​ ② Right-click the project properties, general, select c++17

insert image description here
insert image description here

Attention, the current combination of all versions of qt6 and vs2022: only supports output 64 as an application!


Notes Reference Article 1: Author Linghu Head

Notes Reference Article 2: Author Yan Youjin Yi Wuqiong

If there is any infringement, please contact me to delete the relevant bloggers, new bloggers, please take care, thank you.


Articles stop at scenery, youth blooms now

insert image description here

Guess you like

Origin blog.csdn.net/qq_45491628/article/details/128689834