1

Problem: QtCreator seems to not compile with C++11 standard though Config += c++11 is set in the projects .pro file.

Background: The global definition of the scoped enums are in a seperate header file global_definitions.h:

// ...
enum class dr_items { CROSSHAIR,
                  GRID,
                  LABELS,
                  DATA,
                  AMOUNT // count element
                };

This file produces a warning for every scoped enum, but no error:

/path/global_definitions.h:7: warning: scoped enums only available with -std=c++11 or -std=gnu++11
enum class dr_items { CROSSHAIR,
^

The error occurs on the first usage of the scoped enum in file oscscene.cpp:

#include "oscscene.h"
#include "global_definitions.h"

// ...

for(int i=0;i++;i<dr_items::AMOUNT){
    // ...

with the error output

 /path/oscscene.cpp:9: error: 'dr_items' is not a class or namespace
 for(int i=0;i++;i<dr_items::AMOUNT){
                   ^

Projects .pro file:

QT       += core gui
CONFIG   += c++11
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

Versions:

  • OS is xubuntu 15.10
  • QtCreator version is 3.5.0
  • Qt version is 5.4.2
  • G++ version is 5.2.1
  • Gcc version is 5.2.1
  • make is version 4.0
  • qmake is version 2.01a, but seems to refer to Using Qt version 4.8.6 in /usr/lib/x86_64-linux-gnu when called from console.
  • 2
    Other answers suggest `QMAKE_CXXFLAGS += -std=c++11` ([here](http://stackoverflow.com/q/16948382/1171191) and [here](http://stackoverflow.com/q/17510897/1171191)). – BoBTFish Apr 07 '16 at 08:33
  • There's a 1:1 correspondence between a qmake binary and a Qt installation. If your project builds using Qt 5.4, then Qt Creator is using its particular qmake. This might not be the default qmake in your shell PATH. You can easily check what qmake is Qt Creator using for a particular Kit/Qt Version. – Kuba hasn't forgotten Monica Apr 07 '16 at 13:09

1 Answers1

0

Since qmake seems to use Qt 4.6 instead of Qt5, which supports Config += c++11, the solution is to add

QMAKE_CXXFLAGS += -std=c++11

in the projects .pro file,as BoBTFish commented. This solves the problem.

  • These are old Qt 4 recommendations. This is a hacky solution based on the qmake version you're using. Better use `CONFIG += c++11` and make sure you properly configure your Qt kit to use the qmake bundled with Qt 5.4. See e.g. http://doc.qt.io/qtcreator/creator-project-qmake.html#setting-up-new-qt-versions – Simon Warta Apr 08 '16 at 17:54