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();
}
@ -
I am returning to this old topic because I have a similar need.
I use the Qt Installer Framework to install my Qt application written in C++.
I should point out that with the Qt Installer Framework, you can create two types of installers: “online”, which downloads what it needs to install from a remote repository, and “offline”, which contains everything it needs.
Offline installers have one drawback: they do not allow you to “update” from an older version to a newer one. As a result, if the software is already installed, you have to uninstall the previous version before installing a new one.
At the moment, I cannot create an “online” installer (which would solve the problem), so I have come up with a workaround for the “offline” installer which, thanks to a Qt script, silently uninstalls the old version.Now, I need to insert a few seconds of “sleep” into the Qt script to give the uninstaller, which runs in the background, time to do its job. This is because users (including myself) are often a little too quick to move forward with the installation process and are told that “the destination folder is already in use” even though, when they try again a moment later, it is free and available for installation.