Results 1 to 12 of 12

Thread: Is there any way to abort QScriptValue::call() ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Is there any way to abort QScriptValue::call() ?

    Qt Code:
    1. class Object : public QObject {
    2. Q_OBJECT
    3. public:
    4. Object() {
    5. connect(&timer, SIGNAL(timeout()), this, SLOT(abort()));
    6. engine.setProcessEventsInterval(1000);
    7. fun = engine.evaluate("(function() { while(true); })");
    8. }
    9. void startEval() {
    10. timer.start(1000);
    11. qDebug() << "is callable?" << fun.isFunction();
    12. QScriptContext *context = engine.pushContext();
    13. QScriptValue v = context->activationObject();
    14. v.setProperty("fun", fun);
    15. engine.evaluate("fun()");
    16. engine.popContext();
    17.  
    18. }
    19. private slots:
    20. void abort() {
    21. bool ev = engine.isEvaluating();
    22. qDebug() << "isEvaluating?" << ev;
    23. qDebug() << "Aborting evaluation";
    24. engine.abortEvaluation();
    25. }
    26. private:
    27. // ...
    28. QScriptValue fun;
    29. //...
    30. };
    To copy to clipboard, switch view to plain text mode 

    This calls the function and aborts it after one second. QScriptValue::call() itself doesn't seem abortable as it is executed using different JavaScriptCore method than evaluate(). If you want more flexibility you can probably make your function the activation object itself, set needed arguments and trigger the context (somehow).
    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.


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

    lukass (29th February 2012)

Similar Threads

  1. How to get QScriptValue property changes
    By enamored in forum Qt Programming
    Replies: 0
    Last Post: 16th February 2012, 06:42
  2. QNetworkAccessManager timeout/abort
    By codeslicer in forum Qt Programming
    Replies: 2
    Last Post: 16th May 2011, 13:20
  3. QTScript - getting the name of a QScriptValue
    By android_ in forum Qt Programming
    Replies: 7
    Last Post: 28th October 2009, 14:24
  4. Abort QDialog in the constructor
    By Tino in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 15:36
  5. QScriptValue with simple typedef types
    By JohannesMunk in forum Newbie
    Replies: 9
    Last Post: 14th May 2009, 15:07

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.