QScript and COM access to Q_PROPERTY
-
I'm changing my implemention from this:
@// OLD implementation
class Bar : public QObject
{
Q_OBJECT//...
}
class Foo : public QObject
{
Q_OBJECTpublic:
Foo() { myBar.setParent(this); myBar.setObjectName("myBar");
Bar myBar;
}@
to this:
@// NEW implementation
class Bar : public QObject
{
Q_OBJECT//...
}
class Foo : public QObject
{
Q_OBJECT
Q_PROPERTY(Bar* myBar READ myBarPtr) // ok for COM
Q_PROPERTY(QObject* myBarScript READ myBarPtr) // ok for QScriptpublic:
Foo() {}
private:
Bar myBar;
Bar* myBarPtr() {return &myBar;}
}@Foo is a scriptable object.
With the OLD implemention I could easily access the myBar child from foo objects in my scripts. This is because: [QUOTE]"Accessing Child QObjects":http://qt-project.org/doc/qt-4.8/scripting.html#accessing-child-qobjects
Every named child of the QObject (that is, for which QObject::objectName() is not an empty string) is by default available as a property of the QtScript wrapper object.[/QUOTE]
But with NEW implementation, it's not automatic. Looks like I have to go through the full package: Q_DECLARE_METATYPE, qRegisterMetaType, qScriptRegisterMetaType, etc.I can avoid it if I declare the property as a QObject, it will work fine (just like the OLD implementation). "This link":http://www.archivum.info/qt-interest@trolltech.com/2008-03/00215/Re-QtScript--returning-a-QObject--back-to-a-script.html says that automatic conversion to from Bar* to QObject* is not possible.
But, I want the same Q_PROPERTY to be correctly exposed to my COM object created with a QAxServer. "The manual":http://qt-project.org/doc/qt-5/activeqt-server.html#data-types shows that QObject* is not a supported data types for properties