Where in Qt can I specify additional compiler options? Like for example -std=c++0x?
-
4in Qt designer? Netbeans? What are you using as an IDE? – Jay Jul 07 '11 at 16:42
-
7Do you mean in a `qmake` file? – Fred Foo Jul 07 '11 at 16:42
-
I don't know what exactly TS meant, but I'd like to know to know how to specify compiler options in a .pro file. – Violet Giraffe Jul 07 '11 at 16:46
-
@all sorry I didn't mention, I'm using QtDesigner – smallB Jul 07 '11 at 16:51
3 Answers
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++

- 791
- 4
- 4
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

- 7,665
- 1
- 29
- 43
-
Even if it is obvious, the documentation is here : http://doc.qt.io/qt-5/qmake-variable-reference.html – SR_ Feb 16 '18 at 17:00
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.

- 8,604
- 10
- 63
- 130

- 1,577
- 16
- 32