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. Unable to handle unregistered datatype on QMap typedef
QtWS25 Last Chance

Unable to handle unregistered datatype on QMap typedef

Scheduled Pinned Locked Moved Solved General and Desktop
metatype
3 Posts 2 Posters 1.3k Views
  • 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
    Max13
    wrote on last edited by
    #1

    I'm trying to use a typedef on QMap with QMetaProperty, and I keep getting this error:

    QMetaProperty::read: Unable to handle unregistered datatype 'TimePairMap' for property 'Schedule::times'

    Here is the class in which the typedef is defined:

    class Schedule : public AbstractModel
    {
        public:
            typedef QPair<QTime, QTime>     TimePair;
            typedef QMap<QString, TimePair> TimePairMap;
    
        Q_GADGET
        Q_PROPERTY(TimePairMap times READ times WRITE setTimes)
        // Other properties
    
        private:
            TimePairMap     m_times;
            // Other members
    
        public:
            // Constructors, getters, setters
    };
    
    Q_DECLARE_METATYPE(Schedule::TimePairMap)
    Q_DECLARE_METATYPE(Schedule)
    

    Here is how I check:

    int main(int argc, char *argv[])
    {
        QApplication    a(argc, argv);
    
        a.setApplicationName(QStringLiteral("GateHouse"));
        a.setApplicationVersion(QStringLiteral("v2.0"));
        a.setOrganizationDomain(QStringLiteral("gatehouse.oph.ovh"));
        a.setOrganizationName(QStringLiteral("Olympic Palace Hotel"));
        a.setQuitOnLastWindowClosed(true);
        a.setWindowIcon(QIcon(QStringLiteral(":/images/app-icon")));
    
        // Register MetaTypes
        qRegisterMetaType<Schedule::TimePairMap>("Schedule::TimePairMap");
    
        qDebug() << qMetaTypeId<Schedule::TimePairMap>() << QVariant::typeToName(qMetaTypeId<Schedule::TimePairMap>());
        qDebug() << QVariant(qMetaTypeId<Schedule::TimePairMap>(), 0);
        qDebug() << QMetaProperty(Schedule::staticMetaObject.property(1)).readOnGadget(new Schedule);
        return 0;
    
        return a.exec();
    }
    

    Output is:

    1029 QMap<QString,QPair<QTime,QTime> >
    QVariant(QMap<QString,QPair<QTime,QTime> >, )
    QMetaProperty::read: Unable to handle unregistered datatype 'TimePairMap' for property 'Schedule::times'
    QVariant(Invalid)
    

    I tried with and without the qRegisterMetaType<Schedule::TimePairMap>(), with and without Q_DECLARE_METATYPE(Schedule::TimePairMap). Any idea what I'm missing please?

    BTW, no problem at all using Schedule in QMetaProperty or QVariant.

    We all have started by asking questions. Then after some time, we can begin answering them.

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

      Hi,

      Use the fully qualified type in your Q_PROPERTY declaration i.e. Q_PROPERTY(Schedule::TimePairMap times READ times WRITE setTimes).

      That's what you are currently registering.

      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
      • M Offline
        M Offline
        Max13
        wrote on last edited by
        #3

        Thanks a lot @SGaist

        We all have started by asking questions. Then after some time, we can begin answering them.

        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