Solved QFlags is only usable on enumeration types
-
Hi,
I would like to ask you about an error with QFlag.
The following sentence in qt4 compiles:
QTreeWidgetItem *item = new QTreeWidgetItem; QFlags<Qt::ItemFlags> flags (item->flags() );
However, compiling with qt5 it shows the error:
qtcore\qflags.h(96): error C2338: QFlags is only usable on enumeration typesApparently this error is because of an assert:
Q_STATIC_ASSERT_X((std::is_enum<Enum>::value), "QFlags is only usable on enumeration types.");But, Qt::ItemFlags is an defined user type:
enum ItemFlag { NoItemFlags = 0, ItemIsSelectable = 1, ItemIsEditable = 2, ItemIsDragEnabled = 4, ItemIsDropEnabled = 8, ItemIsUserCheckable = 16, ItemIsEnabled = 32, ItemIsAutoTristate = 64, #if QT_DEPRECATED_SINCE(5, 6) ItemIsTristate = ItemIsAutoTristate, #endif ItemNeverHasChildren = 128, ItemIsUserTristate = 256 }; Q_DECLARE_FLAGS(ItemFlags, ItemFlag)
So from my understanding it should work. Anyway, it seems it compiles using "Qt::ItemFlag" instead of "Qt::ItemFlags".
QTreeWidgetItem *item = new QTreeWidgetItem; QFlags<Qt::ItemFlags> flags (item->flags() );
However, someone could please explain why it is happening in qt and it is the right solution?
Thanks in advance.
[edit:koahnig, code tags added]
-
That's because
Qt::ItemFlags
is already a typedef forQFlags<Qt::ItemFlag>
, meaning you can and should use it like this:Qt::ItemFlags flags = item->flags();
-
That is right.
Thank you very much for your help.