Enum issue in VC2012 and MinGW



  • I just switched from VC2012 and MinGW, http://qt-project.org/forums/viewthread/39285/. I just found the issue is not switch the project itself. It is the enum issue. The enum is treated differently in VC2012 edition and MinGW edition!

    In VC2012 edition, we refer an enum value like this: MyEnum status = MyEnum::Value1;.
    But in MinGW edition, it only take this format: MyEnum status = Value1;.

    For example this following line works in VC2012:

    mainWindow->addToolBar(Qt::ToolBarArea::LeftToolBarArea, taskToolBar);

    But it doesn't work in MinGW now.

    How to avoid this confliction?

    Is the C++11 supported by Qt MinGW 5.2.1 by default? or I need to do some configuration?



  • Yeah, you need to add this line to your .pro file:
    @CONFIG += c++11@

    (Because MinGW defaults to old C++ and VC2012 defaults to C++11)

    P.S. The enum is treated differently not because of different compilers, but depending on if you compile for C++11 or not.

    BTW: If you don't want these kind of surprises, you can code so that it compiles ok, regardless of C++11 switched on or not, by not scoping your enums, i.e. like this instead:
    mainWindow->addToolBar(Qt::LeftToolBarArea, taskToolBar);


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.