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. remove timer single shot delay after a condition is met

remove timer single shot delay after a condition is met

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 5 Posters 1.7k Views 2 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.
  • U Offline
    U Offline
    user4592357
    wrote on last edited by
    #1

    i have a button, on click it should check availability of some dependent app, and if it's not loaded, load it, otherwise just execute the functionality of the button

    now, since the app load can take time, i have added 200ms singleShot timer for button actual slot, i have two connections:

    void checkLoad()
    { try to load another app }
    
    void onBtnClick()
    {
      if not loaded, return
      qtimer:: singleShot (200, this, [] { ... });
    }
    

    how can i not have to singleShot when app is loaded? i.e. only have singleShot delay if app was first time loaded, next times i don't wanna have delay

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Don't use a singleShot timer but a QTimer object.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      U 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        Don't use a singleShot timer but a QTimer object.

        U Offline
        U Offline
        user4592357
        wrote on last edited by user4592357
        #3

        @Christian-Ehrlicher
        ok, so in timeout slot, can i call stop()?
        but i want to the click actual slot to execute, just without delay. how does timer help here?

        Christian EhrlicherC 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Rather than relying on some arbitrary delay, can't you establish a communication with that other app to know when it's up and running ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          U 1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            Rather than relying on some arbitrary delay, can't you establish a communication with that other app to know when it's up and running ?

            U Offline
            U Offline
            user4592357
            wrote on last edited by
            #5

            @SGaist
            i do know that info. but the first time the app is loaded, i need to process some initial setup sent from it. that's why the delay in button slots.

            so i do need the delay, but only first time button clicking and app loading

            jsulmJ 1 Reply Last reply
            0
            • U user4592357

              @SGaist
              i do know that info. but the first time the app is loaded, i need to process some initial setup sent from it. that's why the delay in button slots.

              so i do need the delay, but only first time button clicking and app loading

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @user4592357 said in remove timer single shot delay after a condition is met:

              i need to process some initial setup sent from it

              How does it send this initial setup and how do you read it?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • U user4592357

                @Christian-Ehrlicher
                ok, so in timeout slot, can i call stop()?
                but i want to the click actual slot to execute, just without delay. how does timer help here?

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @user4592357 said in remove timer single shot delay after a condition is met:

                but i want to the click actual slot to execute, just without delay. how does timer help here?

                I don't understand - in your question you say you use a singleShot timer to delay something, now you say you won't delay anything. Please clarify what you really need.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                U 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @user4592357 said in remove timer single shot delay after a condition is met:

                  but i want to the click actual slot to execute, just without delay. how does timer help here?

                  I don't understand - in your question you say you use a singleShot timer to delay something, now you say you won't delay anything. Please clarify what you really need.

                  U Offline
                  U Offline
                  user4592357
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher
                  ok i will store the ms delay and set it to x ms initially, and after first time click (when app is already loaded), i wll set the delay to 0ms

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by Christian Ehrlicher
                    #9

                    Or simply delete it after the first click and do you stuff directly.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    U 1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      The question is: since you already get data from that other app, why not also make it communicate that it is ready ? So you don't have that delay at all. You can then disable the button until everything is ready.
                      In your actual situation you will have your users able to click on a button that might do nothing or something with a delay which is not a really nice user experience.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      U 1 Reply Last reply
                      2
                      • Christian EhrlicherC Christian Ehrlicher

                        Or simply delete it after the first click and do you stuff directly.

                        U Offline
                        U Offline
                        user4592357
                        wrote on last edited by
                        #11

                        @Christian-Ehrlicher
                        delete what?

                        Christian EhrlicherC 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          The question is: since you already get data from that other app, why not also make it communicate that it is ready ? So you don't have that delay at all. You can then disable the button until everything is ready.
                          In your actual situation you will have your users able to click on a button that might do nothing or something with a delay which is not a really nice user experience.

                          U Offline
                          U Offline
                          user4592357
                          wrote on last edited by
                          #12

                          @SGaist
                          i enable the buttons because if i disable all, it won't be clear for user what's wrong.
                          the user needs to set an environment variable so the other will be available

                          1 Reply Last reply
                          0
                          • U user4592357

                            @Christian-Ehrlicher
                            delete what?

                            Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            @user4592357 said in remove timer single shot delay after a condition is met:

                            @Christian-Ehrlicher
                            delete what?

                            The timer object? Because you told us you don't need it anymore.

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            1 Reply Last reply
                            0
                            • U Offline
                              U Offline
                              user4592357
                              wrote on last edited by user4592357
                              #14

                              ok, i start the child process start detached.
                              and it looks like the app is started and it continues to send startup configuration even after my first slot (which invokes the child process) has finished.
                              and that's why i have added delay in the actual (2nd) slot

                              so how can i make sure the child process does its initialisation inside the first slot, and not after it has finished?

                              JonBJ 1 Reply Last reply
                              0
                              • U user4592357

                                ok, i start the child process start detached.
                                and it looks like the app is started and it continues to send startup configuration even after my first slot (which invokes the child process) has finished.
                                and that's why i have added delay in the actual (2nd) slot

                                so how can i make sure the child process does its initialisation inside the first slot, and not after it has finished?

                                JonBJ Online
                                JonBJ Online
                                JonB
                                wrote on last edited by JonB
                                #15

                                @user4592357 said in remove timer single shot delay after a condition is met:

                                so how can i make sure the child process does its initialisation inside the first slot, and not after it has finished

                                You can't. You have no control over, or knowledge of, what the child is doing in the way of initialisation or otherwise. Quite apart from, you don't even know how the OS is scheduling time between your process and another process.

                                i.e. only have singleShot delay if app was first time loaded, next times i don't wanna have delay

                                To answer just that: just keep a bool variable to tell you whether it's first time or not, and don't do delay if you say you don't want it after first time.

                                1 Reply Last reply
                                1

                                • Login

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