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
Qt 6.11 is out! See what's new in the release blog

Sleep in QtScript

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 8.6k Views 1 Watching
  • 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
                    • FlincoF Offline
                      FlincoF Offline
                      Flinco
                      wrote on last edited by
                      #10

                      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.

                      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