Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFlags is only usable on enumeration types
Forum Updated to NodeBB v4.3 + New Features

QFlags is only usable on enumeration types

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 721 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    medihe
    wrote on last edited by koahnig
    #1

    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 types

    Apparently 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]

    kshegunovK 1 Reply Last reply
    0
    • M medihe

      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 types

      Apparently 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]

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by VRonin
      #2

      That's because Qt::ItemFlags is already a typedef for QFlags<Qt::ItemFlag>, meaning you can and should use it like this:

      Qt::ItemFlags flags = item->flags();
      

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2
      • M Offline
        M Offline
        medihe
        wrote on last edited by
        #3

        That is right.

        Thank you very much for your help.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved