[Qt-interest] introspection of enums and flags from QVariant?
Girish Ramakrishnan
girish at forwardbias.in
Mon Feb 8 08:52:38 CET 2010
André Somers wrote:
> Hi,
>
> I’m contemplating the following:
>
> I am writing some code that deals with QVariants. Of course, you can put
> pretty much anything in there. You can also register enums and flags to
> the meta type system. However, I notice that introspection on these only
> seems possible using the QMetaObject methods if these flags or enums are
> used as properties. I would like to be able to do this introspection
> also on enums and flags that are just passed around as values in my
> application. Is that possible? I did not notice any method to get to the
> QMetaEnum from a QFlags class. Am I overlooking something?
>
>
I am afraid you have to go through QMetaObject and friends for any moc
introspection. For your requirement, I would suggest using Q_GADGET
instead of Q_OBJECT.
Something like,
class MyTypes {
Q_GADGET
Q_ENUM(MyEnum)
// enum MyEnum and aother stuff.
private:
MyTypes() { } // only a placeholder class
};
Q_GADGET will make moc generate a staticMetaObject which is a
QMetaObject. To introspect, you can use MyTypes::staticMetaObject.
Girish
More information about the Qt-interest-old
mailing list