working with Q_PROPERTY QPair and QList
-
working with Qt5.4.2
i had to add support to a QVariant based serializer, so it can work with QList<QPair<T1, T2> > being T1 and T2 QVariant compatible. The data to serialize is defined as Q_PROPERTY of QObjects
first I found out that Q_PROPERTY dont allow to write a comma on the type... as it recognize it as two parameters.
So i did a workaround using a macro
#define COMMA ,
and defining the Q_PROPERTY as Q_PROPERTY(QPair<qreal COMMA qreal> ...but still, i got "Unable to handle unregistered datatype" when trying to read the property...
so i had to register:
qRegisterMetaType<QPair<qreal,qreal> >("QPair<qreal,qreal>");and got: "unable to save type/unable to load type", so i added
qRegisterMetaTypeStreamOperators<QPair<qreal,qreal> >();And the QPair started to work, just qreal,qreal, of course...
to make QList<QPair<qreal,qreal> > work... i had to register it again as:
qRegisterMetaType<QList<QPair<qreal,qreal> > >("QList<QPair<qreal,qreal> >"); qRegisterMetaTypeStreamOperators<QList<QPair<qreal,qreal> > >();from this point, everything works perfect, but just for QPair<qreal,qreal> and using an awful macro
could it work without any workaround and registering types?
i think that having moc step, it should be easy to remove the COMMA workaround.
, the same for qRegisterMetaType....
or i am overthinking it and there is a straight and easy way...
-
Hi,
What about:
typedef QPair<qreal, qreal> YourClassName; typedef QList<YourClassName> YourClassNameList;Then you can use them more easily
Hope it helps
-
Hi, thx for the reply.
yes, it is another option, and maybe i should jump to use structs straight. As you never know how it will need to grow
but anyway, someone knows where is the moc compiler code?, i am trying to find it... but no success. Just to take a look
-
In the bin folder of your Qt Installation