如何在 Qt Creator 中启用 C++11?

2022-11-21C/C++开发问题
14

QtMQ=="> 本文介绍了如何在 Qt Creator 中启用 C++11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

标题很自我描述.我已经下载了 Qt Creator 2.7.0,我正在尝试编译一些基本的 C++11 代码:

The title is pretty self-descriptive. I've downloaded Qt Creator 2.7.0, and I am trying to compile some basic C++11 code:

int my_array[5] = {1, 2, 3, 4, 5};
for(int &x : my_array)
{
  x *= 2;
}

我收到以下错误:

range based for loops are not allowed in c++ 98 mode

然而,根据这篇文章 此版本的 Qt Creator 支持 C++11.那么如何启用它?

Yet, according to this article this version of Qt Creator supports C++11. So how do I enable it?

推荐答案

根据本站 添加

CONFIG += c++11

到您的 .pro 文件(参见该网页底部).它需要 Qt 5.

to your .pro file (see at the bottom of that web page). It requires Qt 5.

其他答案,建议

QMAKE_CXXFLAGS += -std=c++11(或 QMAKE_CXXFLAGS += -std=c++0x)

也适用于 Qt 4.8 和 gcc/clang.

这篇关于如何在 Qt Creator 中启用 C++11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End
Qt

相关推荐

如何在 Qt 中实现 OpenSSL?
How to implement OpenSSL in Qt?(如何在 Qt 中实现 OpenSSL?)...
2024-08-14 C/C++开发问题
6

如何使用 MinGW 编译器和 SSL 支持静态编译 Qt
how to statically compile Qt using MinGW compiler and SSL support(如何使用 MinGW 编译器和 SSL 支持静态编译 Qt)...
2024-08-14 C/C++开发问题
6

Qt设置QLineEdit的背景颜色
Qt Set Background Color of QLineEdit(Qt设置QLineEdit的背景颜色)...
2024-08-13 C/C++开发问题
5

在 raspberry 中交叉编译的 qt 中构建应用程序时出错
Error while building app in cross-compiled qt in raspberry(在 raspberry 中交叉编译的 qt 中构建应用程序时出错)...
2023-12-03 C/C++开发问题
6

Qt Creator、ptrace:不允许操作.什么是永久解决方案?
Qt Creator, ptrace: Operation not permitted. What is the permanent solution?(Qt Creator、ptrace:不允许操作.什么是永久解决方案?)...
2023-12-03 C/C++开发问题
8

查找从未调用的函数
Find never-called functions(查找从未调用的函数)...
2023-12-03 C/C++开发问题
3