Dumping the dom in Qt Script



  • Good afternoon,
    I've connected the Qt (4.8) script engine up within my application.
    I'm still learning how to make my application accessible from scripts.
    I'd like to debug it by enumerating everything the script engine can see.
    Has anyone else already developed this?

    The documentation says this should work, but it doesn't:
    @var _children = findChildren();
    for (var i = 0; i < _children.length; ++i)
    serialize( _children[i], indentation + ' ' );
    @

    Here's what I have so far:
    @var toType = function(obj) {
    return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()
    }
    // recursively display object structure
    function serialize(node, indentation) {
    var out = indentation + '<' + node + ' type="' + toType(node) + '"' + '>';
    if ( toType(node) == 'object' )
    {
    for ( var prop in node ) {
    out += '\n' + serialize( prop, indentation + ' ' );
    }
    out += '\n' + indentation + '</' + node + '>' + '\n';
    }
    else
    out += node.toString() + '</' + node + '>';
    return out;
    }

    serialize( Game, '' );
    @

    I do get a dump:
    @
    <ClientOgreController(name = "Game") type="object">
    <CameraMan type="string">CameraMan</CameraMan>
    <HudAnimationFinished() type="string">HudAnimationFinished()</HudAnimationFinished()>
    <SkeletonDebug() type="string">SkeletonDebug()</SkeletonDebug()>
    <update() type="string">update()</update()>
    <CameraBookmark() type="string">CameraBookmark()</CameraBookmark()>
    <CameraUp() type="string">CameraUp()</CameraUp()>
    <CameraDown() type="string">CameraDown()</CameraDown()>
    <CameraToTerrain() type="string">CameraToTerrain()</CameraToTerrain()>
    <CameraForward() type="string">CameraForward()</CameraForward()>
    <ScreenCapture() type="string">ScreenCapture()</ScreenCapture()>
    <PhysicsDebug() type="string">PhysicsDebug()</PhysicsDebug()>
    <CameraOrbit() type="string">CameraOrbit()</CameraOrbit()>
    <Execute(const char*) type="string">Execute(const char*)</Execute(const char*)>
    <DebugConsoleTextEntered(QString) type="string">DebugConsoleTextEntered(QString)</DebugConsoleTextEntered(QString)>
    <DebugConsole() type="string">DebugConsole()</DebugConsole()>
    </ClientOgreController(name = "Game")>
    @

    There are some problems with it though:

    • Child objects and slots are reported as strings (See "CameraMan" and "SkeletonDebug()" )
    • Should I be exposing child objects as references or pointers?
      Q_PROPERTY( Mover* CameraMan READ getCameraMan )

    Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.