Results 1 to 4 of 4

Thread: execute build-in javascript function

  1. #1
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default execute build-in javascript function

    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:
    Qt Code:
    1. QJSValue fun = myEngine.evaluate("(function(a, b) { viewsignals.trigger();}");
    2. QJSValueList args;
    3. args << 1 << 2;
    4. fun.call(args);
    To copy to clipboard, switch view to plain text mode 

    Next, I am trying to add "alert" to the function:
    Qt Code:
    1. QJSValue fun = myEngine.evaluate("(function(a, b) { viewsignals.trigger(); alert('completed');}");
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: execute build-in javascript function

    "alert" is a method of "window" object in HTML's DOM. You don't have that in QJSEngine unless you implement it yourself.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    TorAn (22nd March 2016)

  4. #3
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: execute build-in javascript function

    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.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: execute build-in javascript function

    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,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    TorAn (22nd March 2016)

Similar Threads

  1. Lua + C++ Function Execute
    By steadi in forum Newbie
    Replies: 1
    Last Post: 2nd December 2012, 18:44
  2. Replies: 4
    Last Post: 2nd August 2012, 08:42
  3. execute a small piece of javascript code ?
    By cornucopia in forum Qt Webkit
    Replies: 2
    Last Post: 28th February 2012, 15:00
  4. How to execute a small piece of javascript code ?
    By cornucopia in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2009, 11:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.