Results 1 to 6 of 6

Thread: Qt5 and Visual Studion 2022

  1. #1
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Qt5 and Visual Studion 2022

    Hi!

    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 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.

    Thanks!!!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt5 and Visual Studion 2022

    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.
    Last edited by d_stranz; 7th March 2023 at 05:00.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    bleriot13 (8th March 2023)

  4. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt5 and Visual Studion 2022

    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):

    Qt Code:
    1. QMAKE_MSC_VER = 1920
    To copy to clipboard, switch view to plain text mode 

    (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:

    Qt Code:
    1. greaterThan(QMAKE_MSC_VER, 1909) {
    2. # Visual Studio 2017 (15.0) / Visual C++ 19.10 and up
    3. MSVC_VER = 15.0
    4. COMPAT_MKSPEC = win32-msvc2017
    5. QMAKE_CXXFLAGS += -Zc:referenceBinding
    6.  
    7. # Only Visual Studio 2017 version 15.3 / Visual C++ 19.11 & up have support
    8. # for AVX-512. We enable the switches anyway and let configure check if they
    9. # work.
    10. QMAKE_CFLAGS_AVX512F = -arch:AVX512
    11. QMAKE_CFLAGS_AVX512ER = -arch:AVX512
    12. QMAKE_CFLAGS_AVX512CD = -arch:AVX512
    13. QMAKE_CFLAGS_AVX512PF = -arch:AVX512
    14. QMAKE_CFLAGS_AVX512DQ = -arch:AVX512
    15. QMAKE_CFLAGS_AVX512BW = -arch:AVX512
    16. QMAKE_CFLAGS_AVX512VL = -arch:AVX512
    17. QMAKE_CFLAGS_AVX512IFMA = -arch:AVX512
    18. QMAKE_CFLAGS_AVX512VBMI = -arch:AVX512
    19.  
    20. # For now permissive fails as soon as UWP API comes into play. In qtbase this
    21. # API is used in direct2d, but also in multimedia, positioning and sensors.
    22. # We can try again with a later version of Visual Studio.
    23. # QMAKE_CXXFLAGS_STRICTCXX = -permissive-
    24.  
    25. # MSVC partially supports the following, but '__cplusplus' definition is set
    26. # as for C++98 until MSVC fully conforms with C++14, see
    27. # https://developercommunity.visualstudio.com/content/problem/139261/msvc-incorrectly-defines-cplusplus.html
    28. # Support became available in MSVC 2017 15.7:
    29. greaterThan(QMAKE_MSC_VER, 1913) {
    30. QMAKE_CXXFLAGS += -Zc:__cplusplus
    31. QMAKE_CXXFLAGS_CXX14 = -std:c++14
    32. QMAKE_CXXFLAGS_CXX1Z = -std:c++17
    33. }
    34. }
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. greaterThan(QMAKE_MSC_VER, 1919) {
    2. # Visual Studio 2019 (16.0) / Visual C++ 19.20 and up
    3. MSVC_VER = 16.0
    4. QMAKE_CXXFLAGS_CXX2A = -std:c++latest
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 

    Setting QMAKE_MSVC_VER to 1920 will ensure that at least the VS 2019 compiler will be used with the latest C++ version.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. The following user says thank you to d_stranz for this useful post:

    bleriot13 (8th March 2023)

  6. #4
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Qt5 and Visual Studion 2022

    @d_stranz,

    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!

  7. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt5 and Visual Studion 2022

    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.

    Capture.jpg

    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:

    Qt Code:
    1. ..\src\configure -opensource -prefix C:\Qt\5_15_3\5.15.3\msvc2022_64 -nomake examples -nomake tests -skip qtwebengine -skip qtconnectivity
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by d_stranz; 29th March 2023 at 17:46.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  8. #6
    Join Date
    Mar 2024
    Posts
    1
    Qt products
    Qt5
    Platforms
    Android

    Default Re: Qt5 and Visual Studion 2022

    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.

Similar Threads

  1. Replies: 2
    Last Post: 5th March 2021, 23:57
  2. Using Qt 5.4.1 Visual Studio 2013 libs in Visual Studio 2010
    By ^NyAw^ in forum Installation and Deployment
    Replies: 0
    Last Post: 6th March 2015, 11:20
  3. ms visual c++ compile without ms visual studio
    By zzz9 in forum General Programming
    Replies: 2
    Last Post: 12th August 2012, 21:29
  4. How to find if Visual Studion 2008 installed
    By sawerset in forum Newbie
    Replies: 1
    Last Post: 7th December 2008, 19:28
  5. qt in Visual Studion
    By sanjayk in forum Qt Programming
    Replies: 2
    Last Post: 25th November 2008, 10:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.