【发布时间】:2016-04-07 08:29:57
【问题描述】:
问题:尽管在项目 .pro 文件中设置了 Config += c++11,但 QtCreator 似乎无法使用 C++11 标准编译。
背景:作用域枚举的全局定义在单独的头文件 global_definitions.h 中:
// ...
enum class dr_items { CROSSHAIR,
GRID,
LABELS,
DATA,
AMOUNT // count element
};
此文件为每个作用域枚举生成警告,但没有错误:
/path/global_definitions.h:7: warning: scoped enums only available with -std=c++11 or -std=gnu++11
enum class dr_items { CROSSHAIR,
^
在文件 oscscene.cpp 中第一次使用作用域枚举时发生错误:
#include "oscscene.h"
#include "global_definitions.h"
// ...
for(int i=0;i++;i<dr_items::AMOUNT){
// ...
错误输出
/path/oscscene.cpp:9: error: 'dr_items' is not a class or namespace
for(int i=0;i++;i<dr_items::AMOUNT){
^
项目 .pro 文件:
QT += core gui
CONFIG += c++11
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
版本:
- 操作系统是 xubuntu 15.10
- QtCreator 版本为 3.5.0
- Qt 版本为 5.4.2
- G++版本为5.2.1
- Gcc 版本为 5.2.1
- make 是 4.0 版
- qmake 是 2.01a 版,但似乎是指从控制台调用时在 /usr/lib/x86_64-linux-gnu 中使用 Qt 4.8.6 版。
【问题讨论】:
-
qmake 二进制文件和 Qt 安装之间存在 1:1 对应关系。如果您的项目使用 Qt 5.4 构建,那么 Qt Creator 正在使用其特定的 qmake。这可能不是您的 shell PATH 中的默认 qmake。您可以轻松地检查 Qt Creator 使用的 qmake 用于特定的 Kit/Qt 版本。