Unable to handle unregistered datatype on QMap typedef
Solved
General and Desktop
-
I'm trying to use a typedef on
QMap
withQMetaProperty
, 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 withoutQ_DECLARE_METATYPE(Schedule::TimePairMap)
. Any idea what I'm missing please?BTW, no problem at all using
Schedule
inQMetaProperty
orQVariant
. -
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.