Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Timer still running when main QML is not loaded
Forum Updated to NodeBB v4.3 + New Features

Timer still running when main QML is not loaded

Scheduled Pinned Locked Moved QML and Qt Quick
14 Posts 3 Posters 7.5k 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.
  • J Offline
    J Offline
    jr_jags
    wrote on last edited by
    #3

    I tried putting this code on my main QML but still when i load QML2 the timer is not running,

    @
    //This element is stated in my main QML
    Timer {
    ...
    // This makes the timer active only if someloader does not have a source set.
    running: (someloader.source != "QML2.qml")
    ...
    }@

    If I use the this code in my 2nd QML, do i nid to state the timer element in that QML ?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #4

      Is your Loader element really called "someloader"? That was just an example id.

      Oops. and I see an error in the code I gave you. That should have said
      @
      running: (someloader.source == "")
      @

      The timer should be in the same file as the Loader itself. Not in the QML that the Loader actually loads.

      It's hard to give a more detailed answer without knowing how you have your QML constructed. Do you have any sample code you could share of the section you're having trouble with?

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jr_jags
        wrote on last edited by
        #5

        yup i changed the someloader to mainLoader which is the id of my Loader element but still when i click the mousearea that triggers to load the 2nd QML, the timer stops

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #6

          The timer isn't inside the code that the Loader is loading (and unloading), is it?

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jr_jags
            wrote on last edited by
            #7

            @ Timer {
            id: decrementTimer
            interval: 2000 // 2 seconds
            repeat: true
            running: (mainLoader.source != "home_aspin.qml")

                   onTriggered: {
                      // do your decrement code here
                       Storage.setSetting("setting",hungertext.text)
                       JScript.decrementcode();
            
                   }
                   Component.onCompleted: { Storage.initialize() }
                }@
            

            @ MouseArea {
            id: sleep2home
            x: 138
            y: 407
            width: 95
            height: 76
            onClicked: {
            decrementTimer.start();
            mainLoader.source = "QML2";}
            }@

            this is inside my main QML, and i dont put timer codes on my QML2

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on last edited by
              #8

              But the Timer and the MouseArea are in the same file, correct?

              Just trying to make sure I understand the layout fully.

              (If the Timer is in a piece of QML which is loaded by a Loader, and that QML is unloaded, then the timer will stop because it doesn't exist anymore. So the timer has to be persistent somewhere.)

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jr_jags
                wrote on last edited by
                #9

                yup the timer and mousearea is in the same file, ah ok so i nid to create a new timer in the loaded QML to start again the timer,

                thank you again sir

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on last edited by
                  #10

                  No, I don't believe the loaded QML needs to know about the timer at all, does it? I think I'm confused as to what exactly you're needing to do...

                  When do you want the timer to start, and when do you want it to stop?

                  Software Engineer
                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jr_jags
                    wrote on last edited by
                    #11

                    there is no stop, the timer needs to continue until the application is running,

                    the problem is i am using Loader element, and i used loader in viewing multiple QML's, and when i load a new QML the timer stops decrementing numbers

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mlong
                      wrote on last edited by
                      #12

                      Oh, if the timer needs to stay running, just make sure that "running:" is always true and that the Timer element never gets destroyed.

                      Software Engineer
                      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        nhojyer07
                        wrote on last edited by
                        #13

                        jr_jags, I might be able to help you if you let me see your code at school. :D

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          jr_jags
                          wrote on last edited by
                          #14

                          haha, cge, ill show my code to u at school ^ ^

                          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