[Development] QFlags Zero handling

Stephen Kelly steveire at gmail.com
Sat Jan 21 12:30:40 CET 2017


Hi,

Does anyone know why QFlags has a constructor taking a Zero pointer? My 
guess is that it's a hack to make initializing like

 Qt::WindowFlags = 0

work? The problem encountered is that porting tools convert that to 

 Qt::WindowFlags = nullptr

which is undesirable.

 https://mail.kde.org/pipermail/kde-frameworks-devel/2017-January/042091.html

Is there a better solution to that with modern c++?

Thanks,

Steve.



PS:

I mentioned there that Q_NO_TYPESAFE_FLAGS is broken. Attempting to compile

 #define Q_NO_TYPESAFE_FLAGS
 #include <QObject>

does not work as of Qt 5.5. It gives a flood like this:

qnamespace.h: In function ‘const QMetaObject* 
Qt::qt_getEnumMetaObject(Qt::Orientations)’:
qnamespace.h:1689:31: error: redefinition of ‘const QMetaObject* 
Qt::qt_getEnumMetaObject(Qt::Orientations)’
qnamespace.h:1687:31: note: ‘const QMetaObject* 
Qt::qt_getEnumMetaObject(Qt::Alignment)’ previously defined here
qnamespace.h: In function ‘constexpr const char* 
Qt::qt_getEnumName(Qt::Orientations)’:
qnamespace.h:1689:137: error: redefinition of ‘constexpr const char* 
Qt::qt_getEnumName(Qt::Orientations)’
qnamespace.h:1687:134: note: ‘constexpr const char* 
Qt::qt_getEnumName(Qt::Alignment)’ previously defined here
qnamespace.h: In function ‘const QMetaObject* 
Qt::qt_getEnumMetaObject(Qt::DropActions)’:
qnamespace.h:1690:31: error: redefinition of ‘const QMetaObject* 
Qt::qt_getEnumMetaObject(Qt::DropActions)’
qnamespace.h:1687:31: note: ‘const QMetaObject* 
Qt::qt_getEnumMetaObject(Qt::Alignment)’ previously defined here
qnamespace.h: In function ‘constexpr const char* 
Qt::qt_getEnumName(Qt::DropActions)’:

The define could be removed from qflags.h. Perhaps something could be 
changed in qnamespace.h to allow the code to compile instead (and make the 
enum meta objects not available), but it doesn't seem worth it.








More information about the Development mailing list