[Qt-interest] Q_PROPERTIES not visible in QMetaObject
Girish Ramakrishnan
girish at forwardbias.in
Wed Oct 5 08:14:34 CEST 2011
Hi,
On Tue, Oct 4, 2011 at 9:44 PM, Schimkowitsch Robert
<Robert.Schimkowitsch at andritz.com> wrote:
> I have declared a couple of properties in an QObject-subclass, but they do
> not become visible when iterating through all QMetaObject's properties.
>
> I have the class:
>
> class CPel_PictureElement : public CPel_ContainerElement
> {
> Q_OBJECT
> Q_INTERFACES(IPel_Element)
>
> Q_PROPERTY(QString PictureName READ pictureName WRITE setPictureName)
> Q_PROPERTY(QString PictureAuthor READ pictureAuthor WRITE
> setPictureAuthor)
>
> // Constructors, Methods and Members
> }
>
> Q_DECLARE_METATYPE(CPel_PictureElement*)
>
> CPel_ContainerElement, a QGraphicsWidget, and thereby a QObject subclass.
> (It is also a subclass of a registered interface called IPel_Element)).
>
> The class is compiled within a static library (.a-file using MinGW), and
> used in an executable.
>
> There I attempt to read the property information this way:
>
> CPel_PictureElement* pic = new CPel_PictureElement();
>
> for ( int i = 0; i < pic->metaObject()->propertyCount();
> ++i)
> {
> qDebug() << pic->metaObject()->property(i).name();
> }
>
> I only get the properties up to QGraphicsWidget, not the two properties I
> have defined.
>
> I have also tried manually calling
> qRegisterMetaType<CPel_PictureElement*>();
> - doesn't change anything.
>
> Any ideas what might be wrong here?
>
The above code should work. Maybe something to do with your code
linking to stale objects/libraries? I have often seen .pro files setup
in such a way that even though the static library is built, their
executable is NOT relinked. Which, of course, means that the app is
still using some old code.
Also, your problem of missing properties has nothing to do with
qRegisterMetaType.
Girish
More information about the Qt-interest-old
mailing list