Adding extra compiler option in Qt [duplicate]
You can try adding
QMAKE_CXXFLAGS += -std=c++0x
to your .pro file.
However, this should not be used in Qt 5 for enabling specific c++ standard. Instead, c++11
or c++14
in CONFIG
variable to do that. It will enable GNU extensions (-std=gnu++11), but if that is unwanted, also add strict_c++
if you want to disable those. For example, this should pass -std=c++11
to the compiler:
CONFIG += c++11 strict_c++
In your .pro file, you could add:
QMAKE_CXXFLAGS += -std=c++0x
I think every variable in the spec's qmake.conf
can be altered like that.
For example, the win32-g++ spec has, among other variables, these:
QMAKE_CC = gcc
QMAKE_LEX = flex
QMAKE_LEXFLAGS =
QMAKE_YACC = byacc
QMAKE_YACCFLAGS = -d
QMAKE_CFLAGS =
QMAKE_CFLAGS_DEPS = -M
QMAKE_CFLAGS_WARN_ON = -Wall
QMAKE_CFLAGS_WARN_OFF = -w
QMAKE_CFLAGS_RELEASE = -O2
QMAKE_CFLAGS_DEBUG = -g
QMAKE_CFLAGS_YACC = -Wno-unused -Wno-parentheses
QMAKE_CXX = g++
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS
QMAKE_CXXFLAGS_DEPS = $$QMAKE_CFLAGS_DEPS
QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CFLAGS_WARN_ON
QMAKE_CXXFLAGS_WARN_OFF = $$QMAKE_CFLAGS_WARN_OFF
QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE
QMAKE_CXXFLAGS_DEBUG = $$QMAKE_CFLAGS_DEBUG
QMAKE_CXXFLAGS_YACC = $$QMAKE_CFLAGS_YACC
QMAKE_CXXFLAGS_THREAD = $$QMAKE_CFLAGS_THREAD
QMAKE_CXXFLAGS_RTTI_ON = -frtti
QMAKE_CXXFLAGS_RTTI_OFF = -fno-rtti
QMAKE_CXXFLAGS_EXCEPTIONS_ON = -fexceptions -mthreads
QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -fno-exceptions
The way QT deals with compiler options is through the .pro file. It is a double edged sword if I may. It creates a nice abstraction, especially when compiling large projects. The problem is that you have to either look up or memorize how to add the flag. In the case of C++0X, you have to add the following flag to your .pro file:
QMAKE_CXXFLAGS += -std=c++0x
Fortunately most of the flags that you need are automatically added if you use QtCreator.