2

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?

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
nwp
  • 9,623
  • 5
  • 38
  • 68

1 Answers1

2

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.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • 2. Alone makes qmake pass the desired flag. There may be issues with the application not fitting to the Qt library due to different standards being used, but I could not produce such an error. – nwp Mar 14 '17 at 13:43
  • @nwp Of course 2. alone will do it. I listed these options as mutually exclusive: "You can do one of the following". I edited it to emphasize that. "There may be issues with the application not fitting to the Qt library due to different standards being used" Qt is meant to be valid C++11, and that means it's also valid C++14 (with very few odd corner cases that don't apply to Qt). If you worry about binary compatibility - that's unnecessary, those switches don't produce binary-incompatible output. – Kuba hasn't forgotten Monica Mar 14 '17 at 16:19