NetBeans and Qt5


After upgrading from NetBeans 8.0.1 and switching to Qt5 I noticed that the compiler C++ standard switch was set to c++0x and when setting the C++ standard to C++14 in the project settings the compiler standard switch is left out completely with the result that the compilation fails. I’m currently using the g++ 4.8 compiler, the documentation states that c++0x is deprecated and c++11 should be used instead and the switch for experimental C++14 support is c++1y.

Digging through the various make and project files showed the addition of -std=c++11 to QMAKE_CXXFLAGS was made only when the major version of Qt equalled 4. Oddly c++11 is added to a symbol called CONFIG if the major version is 5. These additions are found in qt-Release.pro and qt-Debug.pro project files. If the selected standard is set to C++14 the addition to CONFIG is missing. I haven’t been able to determine where the -std=c++0x comes from.

It’s clear that NetBeans 8.1 and earlier version don’t properly support Qt5. Switching back to Qt4 resulted in the correct standard switches been added for C++11 and C++14, the C++14 failed build failed because g++ 4.8 doesn’t recognise -std=c++14.

NetBeans can be used with Qt5 with the correct settings for the C++ standards. First set the standard to default:

Setting C++ standard to default

Setting C++ standard to default

Even if C++11 is be used this will suppress the addition of -std=c++0x. The required C++ standard option can be added using the custom definitions in the expert section of Qt project properties:

Custom definitions

Custom definitions

adding the required compiler switch for C++11:

Adding the C++ standard option

Adding the C++ standard option

The custom definition is truncated in the picture, in full it is:

equals(QT_MAJOR_VERSION, 5) { QMAKE_CXXFLAGS+="-std=c++11"}

The check for Qt 5 can be omitted if you don’t intend to swap between Qt4 and Qt5.

So the correct standards can be set when using Qt5 with NetBeans, experimental C++14 support in g++ 4.8 can also used by using c++1y instead. There are currently 3 g++ branches, the latest versions being 4.9, 5.3 and 6.1, these compilers accept -std=c++11 and -std=c++14, in addition 6.1 accepts -std=c++1z for the forthcoming C++17. The appropriate standard can be set depending on your compiler, if your using 6.1 then the custom definition can be deleted as the default standard id C++14.

In short if your using Qt5 with NetBeans always set the C++ compiler standard to default and specify the standard you want to use in Qt custom definitions.

Advertisements

Posted 9 June 2016 by element90 in Development, Linux

Tagged with , , , , ,

%d bloggers like this: