Moc generates uncompilable code
I have a class defined inside a namespace which has properties of the type from the same namespace:
Code:
// inside the included file
Q_DECLARE_METATYPE(Core::Vector)
// inside particle.h
namespace Core {
class Particle {
Q_OBJECT
Q_PROPERTY(Core::Vector position READ position WRITE setPosition)
public:
....
};
}
But when trying to compile I'm getting the following error:
particle.moc|43| error: ‘staticMetaObject’ is not a member of ‘Core’
Inside particle.moc there is the following fragment:
Code:
static const QMetaObject *qt_meta_extradata_Core__Particle
[] = { &Core::staticMetaObject,0
};
{ &Body::staticMetaObject, qt_meta_stringdata_Core__Particle,
qt_meta_data_Core__Particle, qt_meta_extradata_Core__Particle }
};
This looks like wrong code. I have no idea why moc generates it.
Thanks in advance for any help.
Re: Moc generates uncompilable code
After some more experiments I've found that the problem appears when Core::Vector and Q_DECLARE_METATYPE(Core::Vector) are in different files. When they are in the same file everything compiles OK.
Is this expected behaviour ? It seems that documentation says nothing about it.
Re: Moc generates uncompilable code
Quote:
Originally Posted by
Vladimir
It seems that documentation says nothing about it.
Not quite, it says:
Quote:
Ideally, this macro should be placed below the declaration of the class or struct. If that is not possible, it can be put in a private header file which has to be included every time that type is used in a QVariant.
I guess the problem is that the code generated by moc doesn't include that other header file.
Re: Moc generates uncompilable code
Quote:
Originally Posted by
jacek
Not quite, it says:
Yes, I've missed this. Thanks for pointing me to it.
Quote:
Originally Posted by
jacek
I guess the problem is that the code generated by moc doesn't include that other header file.
No, .moc file is included in .cc file which includes all required headers. Moc generates a reference to Core::staticMetaObjec where it obviously should be Core::Particle::staticMetaObject. Very strange that it is related to Q_PROPERTY.
My original goal was to put Q_DECLARE_METATYPE into different header because I want to have a subset of my API which is independent of Qt.
Re: Moc generates uncompilable code
class Particle is not derived from QObject.
Re: Moc generates uncompilable code
Quote:
Originally Posted by
ChristianEhrlicher
class Particle is not derived from QObject.
No, I's derived from QObject.
Re: Moc generates uncompilable code
Quote:
Originally Posted by
Vladimir
No, I's derived from QObject.
Where?
Code:
namespace Core {
class Particle {
Q_OBJECT
Q_PROPERTY(Core::Vector position READ position WRITE setPosition)
public:
....
};
}