Creating a QtScript argument object?



  • Good afternoon all,
    I'm trying to implement setTimeout() (to mimic the web browser function).
    My function gets called and is working correctly except for one issue.
    I can't figure out how to construct the "argument object" when you call a function with parameters.
    I'm beginning to feel like the guy in the Monty Python script where he goes looking for the argument clinic... ;)

    Here's the script:
    @setTimeout( function(pb){ pb.Text = "Goodbye World"; }, 2000 );@

    My function is called. I get parameters, which include a QScriptValue object that represents the function call, and one with the delay value (2000). The function has a parameter (pb). How do I get the argument object/script context for the anonymous function?

    @QScriptValue setTimeout( QScriptContext* ctx, QScriptEngine* eng )
    {
    qDebug() << ctx->backtrace();

    QScriptValue timer( QScriptValue::UndefinedValue );
    QScriptValue argDelay = ctx->argument( 1 );
    if ( argDelay.isNumber() )
    {
    uint32_t delay = argDelay.toUInt32();
    QScriptValue argFunction = ctx->argument( 0 );
    if ( argFunction.isFunction() )
    {
    QScriptValueIterator it( argFunction );
    while ( it.hasNext() )
    {
    it.next();
    qDebug() << " property:" << it.name() << ": " << it.value().toString();
    }
    }
    }
    }
    @

    output:
    12:41:21: Qt Debug: ("<native>(function (pb) { pb.Text = "Goodbye World"; }, 2000) at -1", "<global>() at 17")
    12:41:21: Qt Debug: property: "arguments" : "null"
    12:41:21: Qt Debug: property: "callee" : ""
    12:41:21: Qt Debug: property: "caller" : "null"
    12:41:21: Qt Debug: property: "length" : "1"
    12:41:21: Qt Debug: property: "name" : ""

    I examined the "arguments" property but that doesn't seem to be it.
    Suggestions are welcome.


Log in to reply
 

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