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. QTreeWidgetItem error while get data
Forum Updated to NodeBB v4.3 + New Features

QTreeWidgetItem error while get data

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 207 Views 1 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.
  • C Offline
    C Offline
    Creatorczyk
    wrote on last edited by
    #1

    Hi,

    I would like my QTreeWidgetItem class objects to hold one of the Animal enum values defined outside the class

    enum Animal{ Cat, Dog, Snake};
    
    QTreeWidgetItem *phaseItem = new QTreeWidgetItem();
    phaseItem->setText(0, "dog);
    phaseItem->setFlags(phaseItem->flags() | Qt::ItemIsUserCheckable | Qt::ItemIsSelectable);
    phaseItem->setCheckState(0, Qt::Unchecked);
    phaseItem->setData(0, Qt::UserRole, Animal::Dog);
    addTopLevelItem(phaseItem);
    

    I connected the signal to the slot and while unchecking the checkbox I would like to get the enum value

    QObject::connect(this, &QTreeWidget::itemChanged, this, &SeriesManager::treeWidgetItemChanged);
    
    void SeriesManager::treeWidgetItemChanged(QTreeWidgetItem *item, int i)
    {
        QVariant v = item->data(0, Qt::UserRole);
        Phase phase = v.value<Animal>();
    }
    

    But get error:

    QtCore\qglobal.h:688: error: static assertion failed: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system
     
    QtCore\qmetatype.h:1476: error: 'qt_metatype_id' is not a member of 'QMetaTypeId<Animal>'
    
    QtCore\qmetatype.h:1476: error: body of constexpr function 'static constexpr int QMetaTypeId2<T>::qt_metatype_id() [with T = Animal]' not a return-statement
    

    How could I reseived my enum data from function "data()"?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi,

      @Creatorczyk said in QTreeWidgetItem error while get data:

      QtCore\qglobal.h:688: error: static assertion failed: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system

      You have here what to do to be able to do what you want.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      • Login

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