Qt-interest Archive, February 2008
QtScript - returning a QObject * back to a script
Message 1 in thread
I'm attempting to do something documented in the QtScript reference and
it's not working. I must not be doing something quite right, or maybe
it's more complicated than it is described in the manual.
I've exposed a global object ("root") through setProperty() as used in
the docs. My "root" QObject subclass has a slot:
Field *field(const QString &name) const;
The field() slot looks up a Field (which is derived from QObject, and
has a "name" property) by name.
In my script I want to write this:
print(root.field("example").name);
Now, my root object's "field" slot is getting called and returning the
Field *, but evaluation of the "name" property results in an "undefined"
result. But the result should be the QString name property of the Field.
If I change my script to this:
print(root.field("example"));
I get this result:
QVariant(Field*)
I'm not sure if that is correct or not, but I can't explain why the
"name" property of the Field won't evaluate.
"root" also has a "name" property, and 'print(root.name);' works fine.
Any ideas?
--
[ signature omitted ]