Hi. I am trying to use QtScript within a Windows application. I would like the script to work with an existing COM object already instantiated in the application.
I am able to use QAxObject to wrap the COM object. Then I set a global public property to provide a method to access the object. For example,
QScriptValue globalObject = globalEngine.globalObject();
QScriptValue objectValue = globalEngine.newQObject( globalCom );
globalObject.setProperty("globalComAlias", objectValue );
QAxObject globalCom = new QAxObject( spExistingComObject );
QScriptValue globalObject = globalEngine.globalObject();
QScriptValue objectValue = globalEngine.newQObject( globalCom );
globalObject.setProperty("globalComAlias", objectValue );
To copy to clipboard, switch view to plain text mode
This actually works quite well when I reference "normal" properties of the COM object, such as script code like:
globalComAlias.Title = "test title"
globalComAlias.Title = "test title"
To copy to clipboard, switch view to plain text mode
However, when the properties are themselves references to COM objects, I get errors like "Reference Error: Title not found". An example script section is:
globalComAlias.SubObject.Title = "test title"
globalComAlias.SubObject.Title = "test title"
To copy to clipboard, switch view to plain text mode
It seems that QtScript does not understand the SubObject. (It seems to be true for anything property that returns an IDispatch*.) The error somewhat makes sense to me-- QtScript doesn't know anything about the subobject. However, unlike the global property for the main object, it isn't clear to me how to provide QtScript the details for the subobject.
I tried a few things like qScriptRegisterMetaType, but either I am doing them incorrectly or that isn't the right angle.
As an aside, the same script works when run under Windows Script, but I would really like to run this under the native QtScript (primarily for the access to the debugger.)
Any thoughts or hints would be appreciated. Thanks.
Bookmarks