Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Unable to handle unregistered datatype on QMap typedef



  • 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.


  • Lifetime Qt Champion

    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.



  • Thanks a lot @SGaist


Log in to reply