简体   繁体   中英

How is possible to force Qt QMake project to use C++98 standard?

I tried this in my .pro and it is being ignored:

TEMPLATE = app
CONFIG += console c++98
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += \
        main.cpp

The simplest solution would be to have a cmake project instead. Then you'd have:

# CMakeLists.txt
cmake_minimum_required(VERSION 3.1)

project(foo)
add_executable(${PROJECT_NAME} "main.cpp")
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 98)

Qt Creator supports cmake projects, thus there's no advantage to using qmake for such projects anymore. After all, the Qt dependency is specious - it's a dependency on qmake and nothing else, and qmake only comes bundled with Qt's Base module.

For qmake, you have to set the compiler flags directly:

!win32-msvc: QMAKE_CXXFLAGS += -std=c++98

Theres no way to set it for MSVC, no matter what build tool you're using: it's the limitation of the compiler itself. The only approach is to use a sufficiently old toolset, and optionally override QMAKE_CXX with the compiler's name (not path!). The compiler needs to be in the PATH , ie you'd have to use the toolset's vsvars script to set it up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM