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. OnCompleted doesn't work as expected (??)

OnCompleted doesn't work as expected (??)

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 4 Posters 3.7k 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.
  • S Offline
    S Offline
    skypjack
    wrote on last edited by
    #1

    Hi all,
    I'm coding a splash routine for my application.
    I would like to launch the animation as soon as the main Page has been loaded.
    Splash animation works using States and Transitions.
    Using a MouseArea and the buttonClicked event to change state, it works fine.
    However, triggering state change using Page onCompleted event doesn't work!!
    It seems that the other components are not yet correctly positioned, so anchors and x/y bindings are wrong.
    I don't understand why it works in this way.

    Any suggestions?

    Thanks in advance,
    Michele

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      Do you have a small example you could post showing the problem?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kypeli
        wrote on last edited by
        #3

        You could try to use Component.onCompleted: { }. That, at least for me, works as expected.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          skypjack
          wrote on last edited by
          #4

          Hi mbrasser, sorry but I modified the code because have to do the work!
          However, I used Component.onCompleted inside the page Component but it didn't work.

          Any ideas?
          Components anchors are wrongs moving from "" state to the first state (ie named "first"), as:
          Component.onCompleted: splash.state = "first"
          That doesn't work as expected.

          Do you have a working example that uses images to play a state/transition based splash screen?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kypeli
            wrote on last edited by
            #5

            Why don't you just initialize the state variable of your component with some state instead of trying to do it in the onCompleted method?

            But normally you would not want to initialize the first step to anything, but move to new states as something happens. If you want to go to the default state when something happens in the UI, just set the state to "".

            1 Reply Last reply
            0
            • S Offline
              S Offline
              skypjack
              wrote on last edited by
              #6

              I would like to start the splash animation on load, that's why I'm try changing the state with onCompleted. It seems that Page onCompleted call does not mean that internal components are loaded...

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

                Perhaps the Page component itself (or another component involved) also does some work in onCompleted, and its onCompleted is being called after yours?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  skypjack
                  wrote on last edited by
                  #8

                  Yes, I think so, too. Do you have a workaround to suggest?

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    cpscotti
                    wrote on last edited by
                    #9

                    Hey, I have an idea that might solve your problem (solved for me).

                    Try defining two states on your page, say "bootUp", "splash".
                    @
                    //....
                    states: [
                    State {
                    name: "bootUp"
                    PropertyChanges {
                    target: basePage
                    y: -parent.heigth //just hiding the page..
                    //here you should SET all the proper properties/anchors so that you ENFORCE that
                    //they are SET before you move to the next state
                    }
                    },
                    State {
                    name: "splash"
                    PropertyChanges {
                    target: basePage
                    y: 0
                    }
                    StateChangeScript {
                    name: "startSplashAnimation"
                    script: doAnimation()
                    }
                    }
                    ]
                    @
                    And then try forcing the state change using either Component.onCompleted:
                    @
                    Component.onCompleted: {
                    state = "bootUp"//this will run all the scripts, set all the properties and etc on the bootUp state
                    state = "splash"// you'll see that any scripts called from bootUp will be executed before this line
                    }
                    @

                    or if that doesn't work, try (it's ugly but worked better for me)
                    @
                    onVisibleChanged: {
                    if( visible) {
                    state = "bootUp"
                    state = "splash"
                    }
                    }
                    @

                    If your animations are simple, you can even use something like (to avoid using the StateChangeScript):
                    @
                    transitions: [
                    Transition {
                    from: "bootUp"
                    to: "splash"
                    NumberAnimation {
                    properties: "y"
                    easing.type: Easing.OutExpo
                    duration: 400
                    }
                    }
                    ]
                    @

                    Using some variant of this should make all work. Looks a bit ugly in the beginning but it actually makes sense. Good luck!

                    cpscotti.com/blog/ - Used when I need to kill some time at work :D

                    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