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
-
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?
Thanks
-
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
- Send MessageA;
- Receive MessageB with fieldA=X, fieldB=Y, .....
Anoter example could be
- Send MessageA
- Wait 5 seconds
- Send MessageB
- Receive MessageC
Is this feasible with QtScript?
This is why I thought to sleep() functionThanks in advance
-
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;
timer.setTimeout(milliseconds);
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
timer.start();
loop.exec();
}
@