Sleep in QtScript

  • Hi all,

    I'm developing a Scriptable Application and all works how I need.
    Now I'd like to create a script that executes some steps, waits for a fixed amount of time (sleep like) and continues execution.

    I don't know ECMA Script so well but I don't found a "sleep" function; at the moment the solution I tought is to implement a Q_INVOKABLE method in C++ object who performs sleep and call it from script.

    Any suggestion?

    Thanks in advance

  • Yeah: don't. Just don't sleep. It is a bad idea. Really.

  • Thanks for the answer,

    Probably I didn't provide enough info.
    My purpose is to create a software that enable user to write custom procedure (a test tool).

    I'd like to provide user functionality like loop(), and sleep()/wait().
    I thinking to use ECMAScript for that.

    How do you propose to achieve this?


  • What is the purpose of introducing such a wait? What do you want the host application to do in the mean time? In what thread is the script running?

  • Ok,
    I provide more details.

    I'm developing a message based test tool (a tool that sends a receives data from System to test);
    I developed a backend that reads data structures from XML and perform validation of received data.

    I'd like to create a script engine that allows user to write our test procedure;

    one example could be

    1. Send MessageA;
    2. Receive MessageB with fieldA=X, fieldB=Y, .....

    Anoter example could be

    1. Send MessageA
    2. Wait 5 seconds
    3. Send MessageB
    4. Receive MessageC

    Is this feasible with QtScript?
    This is why I thought to sleep() function

    Thanks in advance

  • You're not answering the question. What is the rest of your code supposed to do in the mean time?

  • HI,

    I'm thinking to launch script evaluation in separate thread

  • Really? So... how do you give access to your applications objects then?

    The only thing I can come up with for a sleep function usuable from scripts but not completely blocking your application, is to create and expose a C++ method like this:
    void sleep(uint milliseconds) {
    QEventLoop loop;
    QTimer timer;
    connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));

  • Ok,

    at the moment it's only an idea. I think I need to develop something in order to try the right way to do this.
    When I have something working I post new questions.

    Thanks a lot for suggestions


Log in to reply

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