Q_PROPERTY typedef
-
The documentation for exposing C++ properties to QML says that:
"Note: Do not use typedef or using for Q_PROPERTY types as these will confuse moc. This may make certain type comparisons fail."
Yet types like QVariantMap are themself typedefs. E.g. QVariantMap is defined like this:
typedef QMap<QString, QVariant> QVariantMap;
I've just tried to use QVariantMap within the Q_PROPERTY macro and it worked fine? Is the documentation on this out of date? What exactly are "type comparisons" in this context?
-
@vinci said in Q_PROPERTY typedef:
Is the documentation on this out of date? What exactly are "type comparisons" in this context?
Probably not out of date. I'd speculate it simply isn't telling the whole story. You can test this:
Make your own typedef and do theQ_DECLARE_METATYPE
andqRegisterMetatype
stuff. Then try to use it as a type in the property. I suspect it should work. E.g. (split and reorder properly):namespace Test { Q_NAMESPACE enum TestEnum { MyValue }; Q_ENUM_NS(TestEnum) } using TestEnum = Test::TestEnum; class Bar : public QObject { Q_OBJECT Q_PROPERTY(TestEnum enum READ enum WRITE setEnum NOTIFY enumChanged) // ... code }; int main( ...) { qRegisterMetaType<TestEnum>("TestEnum"); // Do the QML init and such }
@vinci said in Q_PROPERTY typedef:
Yet types like QVariantMap are themself typedefs. E.g. QVariantMap is defined like this:
Variants are very special.
What exactly are "type comparisons" in this context?
As in whether TestEnum is convertible to
int
, or otherenum
s, or can be streamed to a binary buffer, etc. The metatype reflection stuff basically. -