2
votes

I know there are many duplicates.

This is my Test.pro:

CONFIG += c++14
SOURCES += main.cpp

and my main.cpp:

int main(){}

According to the many duplicates this should give me C++14. However, when I build the project with Qt Creator 4.2.0 with Qt 5.8.0-1 and MinGW gcc 5.3.0-1 installed via the maintenance tool I get

g++ -c -pipe -fno-keep-inline-dllexport -g -std=gnu++1y -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\Test -I. -IC:\Qt\5.8\mingw53_32\include -IC:\Qt\5.8\mingw53_32\include\QtGui -IC:\Qt\5.8\mingw53_32\include\QtANGLE -IC:\Qt\5.8\mingw53_32\include\QtCore -Idebug -IC:\Qt\5.8\mingw53_32\mkspecs\win32-g++ -o debug\main.o ..\Test\main.cpp

which is not the -std=c++14 I expect.

I tried all kinds of tricks from other questions such as

QMAKE_CXXFLAGS_CXX14 = -std=c++14
CONFIG += c++14
QMAKE_CXXFLAGS += -std=c++14

SOURCES += main.cpp

which results in

g++ -c -pipe -fno-keep-inline-dllexport -std=c++14 -g -std=gnu++1y -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\Test -I. -IC:\Qt\5.8\mingw53_32\include -IC:\Qt\5.8\mingw53_32\include\QtGui -IC:\Qt\5.8\mingw53_32\include\QtANGLE -IC:\Qt\5.8\mingw53_32\include\QtCore -Idebug -IC:\Qt\5.8\mingw53_32\mkspecs\win32-g++ -o debug\main.o ..\Test\main.cpp

where the second option overwrites the first, meaning it is still in gnu++1y-mode or just

QMAKE_CXXFLAGS += -std=c++14
SOURCES += main.cpp

which also results in

g++ -c -pipe -fno-keep-inline-dllexport -std=c++14 -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\Test -I. -IC:\Qt\5.8\mingw53_32\include -IC:\Qt\5.8\mingw53_32\include\QtGui -IC:\Qt\5.8\mingw53_32\include\QtANGLE -IC:\Qt\5.8\mingw53_32\include\QtCore -Idebug -IC:\Qt\5.8\mingw53_32\mkspecs\win32-g++ -o debug\main.o ..\Test\main.cpp

I deleted the build directory and the Test.pro.user file to force a build from scratch, nothing gave me C++14.

How do I tell qmake to use C++14?

1

1 Answers

2
votes

The version of Qt that you're using doesn't explicitly support the compiler you're using. You can do either one of the following:

  1. Set both QMAKE_CXXFLAGS_CXX14 and QMAKE_CXXFLAGS_GNUCXX14 in your project:

    win32-g++ {
       QMAKE_CXXFLAGS_CXX14 = -std=c++14
       QMAKE_CXXFLAGS_GNUCXX14 = -std=c++14
    }
    
  2. Edit the default values of those two variables as above, in mkspecs/win32-g++/qmake.conf within your Qt installation folder.

  3. Add a new mkspec copied from win32-g++, targeting your compiler, and build your Qt using it. All the project that use that Qt will then behave correctly w.r.t. C++14 support.