automorphic
automorphic

Reputation: 800

How to Specify MSVC Version in Qt .pro Project File?

The installed version of Visual Studio is 2019 (which supports C++20). How can Qt Creator be told to use it?

The current Qt Kits: enter image description here

The .pro file CONFIG setting accepts c++14:

CONFIG += c++14

But ignores c++17 (or c++20):

CONFIG += c++17

Even specifying it manually:

win32 {
    QMAKE_CXXFLAGS += /std:c++17
}

causes cl to output the error:

cl : Command line warning D9002 : ignoring unknown option '/std:c++17'

And the value of __cplusplus remains unchanged:

__cplusplus=199711L

Example Output:

cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew
   /std:c++17 -Zi -MDd -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc /Fdobj\VideoSync-app.vc.pdb 
  -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -DWIN64 -DAPP_VERSION="1.0.0" -DAPP_VERSION_FULL="1.0.0.214" -DQT_DEPRECATED_WARNINGS -DQT_USE_QSTRINGBUILDER -DQT_DISABLE_DEPRECATED_BEFORE=0x050000 -DQT_QML_DEBUG -DQT_CHARTS_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CONCURRENT_LIB -DQT_CORE_LIB 
  -I..\..\..\MyProj -IS:\opt\dev\MyProj\build\debug -I..\..\..\MyProj\src -I..\..\..\MyProj\src\util -I\opt\opencv\include -I/usr/local/include
  -IC:\Qt\5.14.2\msvc2017_64\include -IC:\Qt\5.14.2\msvc2017_64\include\QtCharts -IC:\Qt\5.14.2\msvc2017_64\include\QtWidgets -IC:\Qt\5.14.2\msvc2017_64\include\QtGui -IC:\Qt\5.14.2\msvc2017_64\include\QtANGLE -IC:\Qt\5.14.2\msvc2017_64\include\QtConcurrent -IC:\Qt\5.14.2\msvc2017_64\include\QtCore -IS:\opt\dev\proj\build\debug\generated -IS:\opt\dev\proj\build\debug\generated -I/include 
  -IC:\Qt\5.14.2\msvc2017_64\mkspecs\win32-msvc -Foobj\ @C:\Users\User.PRO\AppData\Local\Temp\main.obj.16084.359.jom
  main.cpp

  __cplusplus=199711L

Upvotes: 0

Views: 1019

Answers (1)

Luca Carlon
Luca Carlon

Reputation: 9986

When you build your project you need to select the kit you want to use on the left. If the kit you want to use is not in the list, you can activate it for the current project in the "project" section.

Kits are configured in the tab you see in the shot you posted. The kit associates Qt version to the compiler to use. When you select the kit, you select both Qt version and compiler. Please note that the compiler must be compatible with the Qt build in the kit.

You can also try with /std:c++latest: https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=msvc-160, but you must first ensure you are using the proper kit (which defines what compiler you are using).

Upvotes: 1

Related Questions