View Full Version : Qt5 and Visual Studion 2022

6th March 2023, 07:17

I'm considering to migrate from Visual Studio 2015, a rather old version of the Microsoft's IDE and compiler, to 2022.

Although according to this web page (https://doc.qt.io/qt-5/supported-platforms.html) VS2022 is supported by Qt5 (and, in fact, by Qt6) the Qt installer does not offer the pre-compiled libraries for this version. Then, my question is: may I use Visual Studio 2022? If the answer is positive, how? Must I compile Qt on my own? If there is a simpler way (avoiding compiling the whole Qt library) I'd be very grateful if you could tell me how.


6th March 2023, 20:05
The distribution I have is for Qt 5.14.2. I got that when I was a Qt Commercial subscriber, so I downloaded the pre-compiled distribution. Since Qt changed their policies on commercial subscriptions, I dropped that and now use Qt5 under LGPL terms. I haven't needed to build Qt from source.

There is a qt.pro file which will build the whole library, I think. You should be able to open this in QtCreator, set your kits to the VS 2022 compiler, and then build it. Alternatively, you should be able to open the .pro file in VS 2022 itself if you have installed the Qt Visual Studio Tools.

I have VS 2022 and the VS Qt tools, so I will try the build now and let you know what happens.

Edit: Also keep in mind that Qt built against VS 2015 is completely binary compatible with one built against VS 2022, and that is how I am using it. So if you can D/L a pre-compiled binary for VS 2015, use it.

Further edit: After 6 hours of waiting for Visual Studio to finish "creating solution from .pro file" I killed it. Not the way to go. Tomorrow I will try it from QtCreator with a VS 2022 kit.

7th March 2023, 18:12
OK, here's what you do to build an out-of-source Qt on Windows with VS 2022:

0 - Download the Qt 5 source distribution and unzip it where you want it to be.
1 - Open a Visual Studio command prompt window. (Start Menu: Programs -> Visual Studio 2022 -> Visual Studio Tools -> Developer Command Prompt)
2 - CD to your Qt5 "src" directory, then go up one level.
3 - At this level, create a "build" directory and CD to it
4 - Run "..\src\configure -opensource" and reply "y" to the prompt when asked to accept the open source terms.
5 - When this completes, run "nmake" from within the build directory. It will take an hour or more to build Qt.
6 - Optionally, run "nmake install" after this finishes. By default, this will install the binaries to a directory under C:\Qt. There is probably a configure option to change this location; check the Qt documentation.

If you get an error when running the configure script:

"msvc-version.conf loaded but QMAKE_MSC_VER isn't set"

then open the file in the src\qtbase\mkspecs\common\msvc-version.conf and add this line at the top of the file (above where you will see the error message):


(This is for my Qt 5.14.2 distribution. A later Qt5 distribution could have support for Visual Studio 2022 already - look towards the bottom of this file for the last entry of the form below that has something like this:

greaterThan(QMAKE_MSC_VER, 1909) {
# Visual Studio 2017 (15.0) / Visual C++ 19.10 and up
MSVC_VER = 15.0
COMPAT_MKSPEC = win32-msvc2017
QMAKE_CXXFLAGS += -Zc:referenceBinding

# Only Visual Studio 2017 version 15.3 / Visual C++ 19.11 & up have support
# for AVX-512. We enable the switches anyway and let configure check if they
# work.

# For now permissive fails as soon as UWP API comes into play. In qtbase this
# API is used in direct2d, but also in multimedia, positioning and sensors.
# We can try again with a later version of Visual Studio.

# MSVC partially supports the following, but '__cplusplus' definition is set
# as for C++98 until MSVC fully conforms with C++14, see
# https://developercommunity.visualstudio.com/content/problem/139261/msvc-incorrectly-defines-cplusplus.html
# Support became available in MSVC 2017 15.7:
greaterThan(QMAKE_MSC_VER, 1913) {
QMAKE_CXXFLAGS += -Zc:__cplusplus
QMAKE_CXXFLAGS_CXX14 = -std:c++14

In my case (Qt 5.14.2), the last entry is the above, with an entry after that that references the VS 2019 version and modifies a couple of the variables defined above:

greaterThan(QMAKE_MSC_VER, 1919) {
# Visual Studio 2019 (16.0) / Visual C++ 19.20 and up
MSVC_VER = 16.0
QMAKE_CXXFLAGS_CXX2A = -std:c++latest


Setting QMAKE_MSVC_VER to 1920 will ensure that at least the VS 2019 compiler will be used with the latest C++ version.

8th March 2023, 10:04

Wow! What a detailed answer! THANK YOU VERY MUCH for the effort to devoted to it!

I'll give it a try. In the worst case, and since you said (quoting):

"Edit: Also keep in mind that Qt built against VS 2015 is completely binary compatible with one built against VS 2022, and that is how I am using it. So if you can D/L a pre-compiled binary for VS 2015, use it."

I would install Qt5 with pre-compiled binaries for VS2015 (or even VS2019, I guess) because the binary compatibility you talk about should guarantee that even compiling with VS2022 my applications would run without problems.

Once again, THANKS A LOT! I guess that your post above will become a reference source in the future!

8th March 2023, 16:57
No worries. I am using Qt 5.14.2 built with VS 2015 for development with VS 2022. Since about VS 2015, Microsoft made all binaries compiled with the "Platform toolset" parameter set to "v14x" (where "x" is 0 - 3 currently) compatible with each other. So you can link a v140 binary with a v143 binary and all works fine.


I did run into a few glitches. For one, it took hours to build because I did not exclude the examples and there are hundreds of them. It also failed building qtdeclarative (part of QML) because it could not find python. Once I added that to my PATH and reopened the command prompt, that part built. It failed again somewhere further down the line, but all of the major libraries had been built. If I ever do this again for real I will set up a .bat file with an appropriate set of features to build instead of having it build everything. For my desktop app development, I don't use much beyond the core set of functionality.

Edit March 29 2023:

I had to build Qt 5.15 from source because of another project that required that version. I used VS 2022 for the build and followed the steps above. To make it a bit easier, I wrote a little one-line .bat file to start the configuration process:

..\src\configure -opensource -prefix C:\Qt\5_15_3\5.15.3\msvc2022_64 -nomake examples -nomake tests -skip qtwebengine -skip qtconnectivity

After configuring, I started the build in the evening and it was done without errors by the next morning. "nmake install" copied the appropriate files to the "prefix" (install) directory.

When I tried to build the docs (nmake docs) it failed because for some reason dqoc.exe was not built (even though assistant.exe was). So I copied qdoc.exe from my previous Qt5 install into the new install bin directory and all worked fine. There is probably a configure option to fix that.

18th March 2024, 03:32
Installing Qt5 using pre-compiled binaries for Visual Studio 2015 (or maybe even 2019, I suppose) would be my choice, since the binary compatibility you mention should ensure that my apps would function flawlessly even when produced with Visual Studio 2022.

21st March 2024, 22:37
This will of course work, but I am not aware of any precompiled binaries for Qt 5.15. The only thing I can find on the Qt site is source distributions. If you want the 5.15.x LTS (long term support) version, you have to build it yourself.

20th April 2024, 14:24
At last! After days of searching for a solution, I finally found what I was looking for. Thank you.

27th May 2024, 07:09
Qt5 is a popular cross-platform C++ framework used for developing applications with graphical user interfaces (GUIs) and other features. Visual Studio is an integrated development environment (IDE) developed by Microsoft, commonly used for software development in various programming languages, including C++.

To use Qt5 with Visual Studio 2022 for C++ development, you typically follow these steps:

Install Visual Studio 2022: Download and install Visual Studio 2022 from the official Microsoft website.

Install Qt5: Download and install the Qt5 framework from the official Qt website. Make sure to select the appropriate version for your development environment and target platforms.

Set up Qt integration: Qt provides integration plugins for Visual Studio, which allow you to create, build, and debug Qt projects within the Visual Studio IDE. Depending on the version of Visual Studio and Qt you're using, you may need to download and install the appropriate integration plugin from the Qt marketplace or use the Qt Visual Studio Tools extension.

Create a new Qt project: Once Qt is integrated with Visual Studio, you can create a new Qt project from within Visual Studio. Select the appropriate project template based on your requirements (e.g., Qt Widgets Application, Qt Quick Application, etc.).

Configure project settings: Configure your project settings, including Qt version, target platforms, build configurations, and other options as needed.

Write and build your code: Write your C++ code using Qt APIs to create the desired application functionality. You can use Visual Studio's build and debugging features to compile, run, and debug your Qt application.

Deploy your application: Once your application is ready, you can deploy it to your target platforms. Qt provides tools and documentation to help you package and distribute your Qt applications for various operating systems and platforms.

Remember to refer to the official documentation and resources for both Qt and Visual Studio for detailed instructions on setting up and using Qt with Visual Studio 2022. Additionally, make sure to keep your development environment and tools updated to the latest versions to leverage new features and improvements.