Results 1 to 2 of 2

Thread: QtScript and COM objects

  1. #1
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QtScript and COM objects

    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,
    Qt Code:
    1. QAxObject globalCom = new QAxObject( spExistingComObject );
    2. QScriptValue globalObject = globalEngine.globalObject();
    3. QScriptValue objectValue = globalEngine.newQObject( globalCom );
    4. 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:
    Qt Code:
    1. 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:
    Qt Code:
    1. 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QtScript and COM objects

    You probably need to provide some code that will act as a wrapper around the subobject. QScriptClass is a good place to start. Also have a look at the Default Prototypes example, it shows how to make a class scriptable. There are at least three ways to do it.

    In general probably the best overall approach is to provide a complete wrapper over QAxObject. The part that works for you works only because QAxObject exposes its properties as QObject properties. But it won't give you anything defined in QAxBase which I guess is something that is really interesting for you. That's also why accessing subobjects doesn't work -- subobjects are not exposed as Qt properties.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QtScript and creating non QObject based objects
    By tbscope in forum Qt Programming
    Replies: 1
    Last Post: 5th October 2011, 08:20
  2. QtScript: Passing an array of objects to C++
    By Plow in forum Qt Programming
    Replies: 0
    Last Post: 16th April 2010, 12:53
  3. Replies: 0
    Last Post: 25th November 2009, 07:46
  4. Lumina GLSL IDE based on QtScript and dynamic Objects
    By oc2k1 in forum Qt-based Software
    Replies: 0
    Last Post: 12th August 2008, 04:12
  5. Replies: 7
    Last Post: 18th July 2006, 21:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.