在构建qmake项目时如何使用C ++ 14功能? [英] How can I use C++14 features when building qmake projects?

查看:192
本文介绍了在构建qmake项目时如何使用C ++ 14功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的Qt应用程序中使用C ++ 11功能。但是,我想在我的应用程序中使用一些新的C ++ 14功能。



要在Qt应用程序中启用C ++ 11,在 qmake 项目文件中添加一行:

  CONFIG + = c ++ 11 

或以下版本:

  QMAKE_CXXFLAGS + = -std = c ++ 1y 

试图做同样与C ++ 14,但它没有工作。我改变了上述的 qmake 项目:

  CONFIG + = c ++ 14 

或以前版本的



  QMAKE_CXXFLAGS + = -std = c ++ 1y 

当尝试构建项目时,会出现很多以前不存在的编译错误。该项目编译良好,但是,如果我尝试使用任何C ++ 14功能,我得到一个编译错误。这是一个例子:

  template< typename T> 
constexpr T pi = T(3.1415926535897932385);

这是相应的错误:

  main.cpp:7:error:模板声明'constexpr const T pi'
constexpr T pi = T(3.1415926535897932385);
^

如何在使用时启用C ++ 14功能qmake 我使用Qt 5.3.2,Qt Creator 3.2.1和MinGW 4.8.2 32位。

解决方案

Qt Creator 只是一个 IDE



您可以将IDE看作是更聪明的文本编辑器,帮助开发人员调试,构建代码完成,文件管理等。



IDE在编译期间不相关。



重要的是您的编译器

支持许多C ++ 14功能:查看此页面了解支持的C ++ 14功能。 / p>

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.

To enable C++11 in a Qt application, one only needs to add one line in the qmake project file, namely:

CONFIG += c++11

or this for earlier versions:

QMAKE_CXXFLAGS += -std=c++1y

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

or this for earlier versions:

QMAKE_CXXFLAGS += -std=c++1y

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);

This is the corresponding error:

main.cpp:7: error: template declaration of 'constexpr const T pi'
constexpr T pi = T(3.1415926535897932385);  
          ^

How to enable C++14 features when using a qmake project in QtCreator?

I am using Qt 5.3.2, Qt Creator 3.2.1, and MinGW 4.8.2 32 bit.

解决方案

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.

这篇关于在构建qmake项目时如何使用C ++ 14功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆