Problem with Q_GADGET
-
hi
I have a little problem with Q_GADGET macro. Following example:
@class A
{};
class B: public A
{
Q_GADGET
};@that code compiles with compiler error "staticMetaObject" is not an element of A
but wenn i change the code to
@class A
{};
class helper
{
Q_GADGET
};class B: public helper, public A
{
Q_GADGET
};@it compiles with no error. I dont really understand why. Is it important for the moc to have the Q_GADGET class before the other inheritance? Are there other solutions instead of just adding an empty dummy class?
thanks
Felix
-
Q_OBJECT works only for QObject derived classes. This makes QObject the toplevel class in the inheritance hierarchy. As Q_GADGET enables a subset of the meta object system on classes not based on QObject and moc is run anayways, I suspect this holds for those classes too: moc just expects that the base classes are gadgets too.
Adding the Q_GADGET macro to class A should have no impact on your existing software, as it just adds some extra stuff and does not change your existing code. The only drawback might be a binary incompatibility, due to the fact that the class interface changes.