PDA

View Full Version : execute build-in javascript function



TorAn
22nd March 2016, 11:40
I am trying to use QJSEngine to automate part of my application. I exposed the instance of QAction "viewsignals" to JSEngine and this code executes successfully:

QJSValue fun = myEngine.evaluate("(function(a, b) { viewsignals.trigger();}");
QJSValueList args;
args << 1 << 2;
fun.call(args);

Next, I am trying to add "alert" to the function:

QJSValue fun = myEngine.evaluate("(function(a, b) { viewsignals.trigger(); alert('completed');}");

However, when executed, alert does not show up.
What am I doing wrong here?
Thanks

wysota
22nd March 2016, 11:46
"alert" is a method of "window" object in HTML's DOM. You don't have that in QJSEngine unless you implement it yourself.

TorAn
22nd March 2016, 13:02
Aha! Then what is the right approach to automate Qt application using QJSEngine and Qt javascript support? (I am moving away from QScript).

What I want to do is to execute QAction, wait 5 seconds and display "success" message. I wanted to use "setTimeout" and "alert", but all these are "window" object methods.
Any suggestions?

Thanks.

anda_skoa
22nd March 2016, 14:53
You can expose some "global" object that provides you with the functionality that the browser would expose.

If you use QQmlEngine you can even register singletons, etc.

Cheers,
_