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. Call function when StackView.pop

Call function when StackView.pop

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 4 Posters 4.5k 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.
  • AlexorleonA Offline
    AlexorleonA Offline
    Alexorleon
    wrote on last edited by
    #1

    Hi.

    If you make "stackview.push", "Component.onCompleted" will work, but if you do "stackview.pop" then the second time it is not called.
    I need to call the function of the current "Item" when I do "stackview.pop". I can not find the signal I need.

    property int testNum: 1
    
        StackView {
            id: stack
            anchors.fill: parent
            initialItem: view1
    
            onCurrentItemChanged: {
                // I think I need to write something here, but what?
            }
        }
    
        Component {
            id: view1
    
            Rectangle {
                color: "lightblue"
    
                // I need to call this function after stack.pop
                function func() {
                    testNum *= 10
                }
    
                // Component.on ???
    
                // This is called only once
                Component.onCompleted: func()
    
                Text {
                    text: testNum.toString()
                    anchors.centerIn: parent
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: stack.push(view2)
                }
            }
        }
        Component {
            id: view2
    
            Rectangle {
                color: "lightgreen"
    
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        testNum++
                        stack.pop()
                    }
                }
            }
        }
    
    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by
      #2

      The counterpart for Component::onCompleted() is Component::onDestruction().

      AlexorleonA 1 Reply Last reply
      1
      • jpnurmiJ jpnurmi

        The counterpart for Component::onCompleted() is Component::onDestruction().

        AlexorleonA Offline
        AlexorleonA Offline
        Alexorleon
        wrote on last edited by
        #3

        @jpnurmi, I need to call a function that is in "View1" when I go back there.

        1 Reply Last reply
        0
        • ekkescornerE Offline
          ekkescornerE Offline
          ekkescorner
          Qt Champions 2016
          wrote on last edited by
          #4

          my Pages all have a name property

          property string name: "QueueItemDetailPage"
          

          I do not simply a pop() on the stack, I'm calling popOnePage()

          function popOnePage() {
                      var page = pop()
                      if(page.name == "QueueItemDetailPage") {
                          // if using Loader deactivate here or call functions if not using onDeconstruction()
                           page.mySpecialFunction()
                          detailLoader.active = false
                          return
                      }
                     // and also for the next ones
                  } // popOnePage
          

          take a look at some of my sample apps where I'm doing this
          https://appbus.wordpress.com/category/qt-for-mobile/overview/

          ekke ... Qt Champion 2016 | 2024 ... mobile business apps
          5.15 --> 6.9 https://t1p.de/ekkeChecklist
          QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

          1 Reply Last reply
          0
          • jpnurmiJ Offline
            jpnurmiJ Offline
            jpnurmi
            wrote on last edited by
            #5

            Depending on what you're trying to achieve, some of the attached signals introduced in Qt Quick Controls 2.1 in Qt 5.8 might be useful:

            • StackView::activating()
            • StackView::activated()
            • StackView::desctivating()
            • StackView::deactivated()
            • StackView::removed()

            For your particular use case, the last one might be interesting.

            Component {
                id: view2
                Rectangle {
                    StackView.onRemoved: doSomething()
                }
            }
            
            ekkescornerE 1 Reply Last reply
            2
            • jpnurmiJ jpnurmi

              Depending on what you're trying to achieve, some of the attached signals introduced in Qt Quick Controls 2.1 in Qt 5.8 might be useful:

              • StackView::activating()
              • StackView::activated()
              • StackView::desctivating()
              • StackView::deactivated()
              • StackView::removed()

              For your particular use case, the last one might be interesting.

              Component {
                  id: view2
                  Rectangle {
                      StackView.onRemoved: doSomething()
                  }
              }
              
              ekkescornerE Offline
              ekkescornerE Offline
              ekkescorner
              Qt Champions 2016
              wrote on last edited by
              #6

              @jpnurmi
              thx.
              have overlooked these new signals from 2.1

              ekke ... Qt Champion 2016 | 2024 ... mobile business apps
              5.15 --> 6.9 https://t1p.de/ekkeChecklist
              QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

              1 Reply Last reply
              0
              • ibiaI Offline
                ibiaI Offline
                ibia
                wrote on last edited by
                #7

                I do not know if it can help you, in the case you are. But, I think you can use the "depth" property (the signal onDepthChanged) to know if it has increased or decreased.

                1 Reply Last reply
                0
                • AlexorleonA Offline
                  AlexorleonA Offline
                  Alexorleon
                  wrote on last edited by
                  #8

                  Many thanks to all!

                  I forgot to say that I use Qt 5.7. If it is necessary.
                  I don't understand why I didn't get it right away :)

                  property int testNum: 1
                  
                      StackView {
                          id: stack
                          anchors.fill: parent
                          initialItem: view1
                  
                          function ff() {
                              // if (depth or name ...) {}
                              currentItem.func()
                          }
                      }
                  
                      Component {
                          id: view1
                  
                          Rectangle {
                              color: "lightblue"
                  
                              function func() {
                                  testNum *= 10
                              }
                  
                              Component.onCompleted: func()
                  
                              Text {
                                  text: testNum.toString()
                                  anchors.centerIn: parent
                              }
                              MouseArea {
                                  anchors.fill: parent
                                  onClicked: stack.push(view2)
                              }
                          }
                      }
                      Component {
                          id: view2
                  
                          Rectangle {
                              color: "lightgreen"
                  
                              MouseArea {
                                  anchors.fill: parent
                                  onClicked: {
                                      testNum++
                                      stack.pop()
                  
                                      // Additionally call the function
                                      stack.ff()
                                  }
                              }
                          }
                      }
                  

                  jpnurmi, in the future I will go to Qt 5.8

                  ekkescorner, a wonderful blog, I will definitely read it.

                  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