Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating a QtScript argument object?
Qt 6.11 is out! See what's new in the release blog

Creating a QtScript argument object?

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 920 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jsprenkle
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved