[Qt-interest] Use myClass* with QMetaProperty

Ender EREL erelender at yahoo.com
Thu Dec 18 10:21:09 CET 2008


Hi everybody,

I am trying to create a generic object editor .dll plugin for my
application. The idea is, the editor gets a QObject* (the actual object
is a class derived from QObject) and uses QMetaObject to get the
properties of the object and generate corresponding widgets. But there
is a restriction, the editor will know that the object is derived from
QObject but will not know what class it actually is. There is no problem
when a member is of primitive types or Qt classes, but i can't get it to
work with custom classes derived from QObject. Let me illustrate it with
an example:

class A : public QObject
{
.
(some primitive members)
.
};
Q_DECLARE_METATYPE(A)


class B : public QObject
{
.
(some primitive members)
.
A* myA;
}

All members have getters/setters, Q_OBJECT and Q_PROPERTY macros are
used accordingly.

The editor gets a QObject* (actually a B*) and creates widgets for other
members. Then it tries to get the myA member using
mObject->property("myA") but the returned Qvariant is invalid, and
output shows this message:

QMetaProperty::read: Unable to handle unregistered datatype 'A*' for
property 'B::myA'

I also tried using Q_DECLARE_METATYPE(A*) but it did not work either.

BTW i am using Qt 4.3.0

I cant figure out how to solve this problem, any help would be appreciated.

-- 
ender



More information about the Qt-interest-old mailing list