How can I use C++14 features when building qmake projects?
Qt Creator is just an IDE.
You can think of IDEs as "smarter text editors" that aid the developer with debugging, building, code completion, file management and so on.
IDEs are irrelevant during compilation.
What matters is your compiler. And it is independent from your IDE.
g++ 4.8.x does not support many C++14 features: check out this page to learn what C++14 features are supported.
How to set qmake to C++14 with recent MinGW?
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:
Set both
QMAKE_CXXFLAGS_CXX14
andQMAKE_CXXFLAGS_GNUCXX14
in your project:win32-g++ {
QMAKE_CXXFLAGS_CXX14 = -std=c++14
QMAKE_CXXFLAGS_GNUCXX14 = -std=c++14
}Edit the default values of those two variables as above, in
mkspecs/win32-g++/qmake.conf
within your Qt installation folder.Add a new
mkspec
copied fromwin32-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.
How to enable C++14 with older Qt? Qmake incompatible with C++14
I use this in one of my projects. In the .pro
file:
CONFIG += c++14
# Qt 5.3 and lower doesn't recognize "c++14". Use c++11 and then replace
# the compiler flags with c++14.
contains(QT_MAJOR_VERSION, 5):lessThan(QT_MINOR_VERSION, 4) {
CONFIG += c++11
QMAKE_CXXFLAGS_CXX11 = $$replace(QMAKE_CXXFLAGS_CXX11, "std=c\+\+11", "std=c++1y")
QMAKE_CXXFLAGS_CXX11 = $$replace(QMAKE_CXXFLAGS_CXX11, "std=c\+\+0x", "std=c++1y")
}
# Qt 4 doesn't even know about C++11, so just add c++14 directly.
contains(QT_MAJOR_VERSION, 4) {
QMAKE_CXXFLAGS += -std=c++1y
}
If you don't care about Qt4, remove the last part.
Obvious this only works with GCC and Clang. Other compilers would need different handling.
Unsupported Build Type when building a project with qmake
Qt 5.2.1 is unsupported as of writing this. See their issue tracker for details:
Switch to Qt >= 5.1 #286
Also, if you happen to use VS2013, that is also unsupported.
When building Qt programs, how could I use former qmake flags in cmake?
Since you talk about CMake, I assume you talk about Qt 6. Qt 6 doesn't support the native Win32 Bluetooth API anymore, see also https://doc-snapshots.qt.io/qt6-dev/whatsnew62.html :
Win32 backend was removed. As a consequence, there is no longer support for Qt Bluetooth using MinGW.
Enable C++14 in Qt Creator 4.0 Clang Static Analyzer using CMake
try to add -std=c++14
in Option > C++ > Code Model.
Mine is like this :
-Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-unused-macros -Wno-newline-eof -Wno-exit-time-destructors -Wno-global-constructors -Wno-gnu-zero-variadic-macro-arguments -Wno-documentation -Wno-shadow -Wno-missing-prototypes -Wsuggest-override -std=c++14
Note :
You have to reopen each file for it to take effect.
If you can't edit it, you have to enable the plugin "Code model" first (help > about plugins...) and restart QtCreator
Configuring the GCC compiler switches in Qt, QtCreator, and QMake
It boils down to reading the manual. Instead of using CXXFLAGS
in the .pro file, you need to use QMAKE_CXXFLAGS
as in:
main.cpp:
#include <cinttypes>
int main() { return 0; }
main.pro:
SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++0x
Related Topics
How to Program for Windows Phone 7 in Standard C++ Only
How to Tell Pyximport to Use the Cython --Cplus Option
Passing a Lambda into a Function Template
Removing '#Include <Algorithm>' Doesn't Break the Code
Allocating Struct with Variable Length Array Member
Different Compiler Behavior for Expression: Auto P {Make_Pointer()};
Qsqldatabase: Qmysql Driver Not Loaded on Ubuntu 15.04 64Bits
C++ When Is It Ok to Extend the 'Std' Namespace
What Is the Reason Behind Cbegin/Cend
Default Member Values Best Practice
Oracle Oci, Bind Variables, and Queries Like Id in (1, 2, 3)
Iterator Adapter to Iterate Just the Values in a Map
Lambdas and Capture by Reference Local Variables:Accessing After the Scope
What's the Difference Between Parentheses and Braces in C++ When Constructing Objects
Covariant Return Type and Type Conversion
Date/Time Conversion: String Representation to Time_T
Want to Efficiently Overcome Mismatch Between Key Types in a Map in Boost.Interprocess Shared Memory