Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sleep in QtScript
Forum Updated to NodeBB v4.3 + New Features

Sleep in QtScript

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 5.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mcosta
    wrote on last edited by
    #1

    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

    Once your problem is solved don't forget to:

    • Mark the thread as SOLVED using the Topic Tool menu
    • Vote up the answer(s) that helped you to solve the issue

    You can embed images using (http://imgur.com/) or (http://postimage.org/)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Yeah: don't. Just don't sleep. It is a bad idea. Really.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mcosta
        wrote on last edited by
        #3

        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

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          What is the purpose of introducing such a wait? What do you want the host application to do in the mean time? In what thread is the script running?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mcosta
            wrote on last edited by
            #5

            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

            1. Send MessageA;
            2. Receive MessageB with fieldA=X, fieldB=Y, .....

            Anoter example could be

            1. Send MessageA
            2. Wait 5 seconds
            3. Send MessageB
            4. Receive MessageC

            Is this feasible with QtScript?
            This is why I thought to sleep() function

            Thanks in advance

            Once your problem is solved don't forget to:

            • Mark the thread as SOLVED using the Topic Tool menu
            • Vote up the answer(s) that helped you to solve the issue

            You can embed images using (http://imgur.com/) or (http://postimage.org/)

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              You're not answering the question. What is the rest of your code supposed to do in the mean time?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mcosta
                wrote on last edited by
                #7

                HI,

                I'm thinking to launch script evaluation in separate thread

                Once your problem is solved don't forget to:

                • Mark the thread as SOLVED using the Topic Tool menu
                • Vote up the answer(s) that helped you to solve the issue

                You can embed images using (http://imgur.com/) or (http://postimage.org/)

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  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();
                  }
                  @

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mcosta
                    wrote on last edited by
                    #9

                    Ok,

                    at the moment it's only an idea. I think I need to develop something in order to try the right way to do this.
                    When I have something working I post new questions.

                    Thanks a lot for suggestions

                    Max

                    Once your problem is solved don't forget to:

                    • Mark the thread as SOLVED using the Topic Tool menu
                    • Vote up the answer(s) that helped you to solve the issue

                    You can embed images using (http://imgur.com/) or (http://postimage.org/)

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved