我目前在我的 Qt 应用程序中使用 C++11 功能.但是,我想在我的应用程序中使用一些新的 C++14 特性.
I'm currently using C++11 features in my Qt applications. However, I'd like to use some of the new C++14 features in my applications.
要在Qt应用程序中启用C++11,只需在qmake项目文件中添加一行,即:
To enable C++11 in a Qt application, one only needs to add one line in the qmake project file, namely:
CONFIG += c++11
或者对于早期版本:
QMAKE_CXXFLAGS += -std=c++1y
我已经尝试用 C++14 做同样的事情,但是没有用.我像这样更改了 qmake 项目的上述行:
I already tried to do the same with C++14, but it didn't work. I changed the above mentioned line of the qmake project like this:
CONFIG += c++14
或者对于早期版本:
QMAKE_CXXFLAGS += -std=c++1y
之后,在尝试构建项目时出现了许多以前不存在的编译错误.该项目编译正常,但是,如果我尝试使用任何 C++14 功能,则会出现编译错误.这是一个例子:
After that, lots of compilation errors, that did not exist before, appear when trying to build the project. The project compiles fine, however, if I try to use any C++14 features, I get a compilation error. This is an example:
template<typename T>
constexpr T pi = T(3.1415926535897932385);
这是相应的错误:
main.cpp:7: error: template declaration of 'constexpr const T pi'
constexpr T pi = T(3.1415926535897932385);
^
在 QtCreator 中使用 qmake 项目时如何启用 C++14 功能?
How to enable C++14 features when using a qmake project in QtCreator?
我使用的是 Qt 5.3.2、Qt Creator 3.2.1 和 MinGW 4.8.2 32 位.
I am using Qt 5.3.2, Qt Creator 3.2.1, and MinGW 4.8.2 32 bit.
Qt Creator 只是一个 IDE.
您可以将 IDE 视为更智能文本编辑器",帮助开发人员进行调试、构建、代码完成、文件管理等.
You can think of IDEs as "smarter text editors" that aid the developer with debugging, building, code completion, file management and so on.
IDE 在编译过程中无关紧要.
IDEs are irrelevant during compilation.
重要的是您的编译器.它独立于您的 IDE.
g++ 4.8.x 不支持许多 C++14 功能:查看此页面以了解支持哪些 C++14 功能.
g++ 4.8.x does not support many C++14 features: check out this page to learn what C++14 features are supported.
这篇关于构建 qmake 项目时如何使用 C++14 功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!