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. Passing parameters with StackView

Passing parameters with StackView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 4 Posters 3.6k Views
  • 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.
  • D Offline
    D Offline
    davidino
    wrote on 15 Jul 2018, 18:16 last edited by davidino
    #1

    Goodmonring,
    I've create a stackView, as shown in the code below. If I simply pass the qrc link it works perfectly, but when I try to load some properties together with the page, it failed. I tried to see the documentation and examples but to me it looks that everything is ok.

    import QtQuick 2.6
    import QtQuick.Controls 2.0
    import "imageView/."            // QTBUG-34418, singletons require explicit import to load qmldir file
    
    ApplicationWindow {
    
        readonly property alias pageStack: stackView
    
        readonly property int playerPage: 0
        readonly property int songControllerPage: 1
    
        id: app
        visible: true
        width: 1368
        height: 768
        color: Style.windowBackground
    
        StackView {
            id: stackView
            anchors.fill: parent
            initialItem: Qt.resolvedUrl("qrc:/qml/musicPlayer/PlayerPage.qml"); 
        }
    
        onClosing: {
            if (Qt.platform.os == "android") {
                if (stackView.depth > 1) {
                    close.accepted = false
                    stackView.pop()
                }
            }
        }
    }
    

    The method used in PlayerPage.qml to change page is the following:

    MouseArea {
               id: playArea
               anchors.fill: parent
               onReleased:
               {
                         pageStack.push({item: "qrc:/qml/musicPlayer/SongController.qml",
                         properties: {currentIndex: index, items: objects firstIndexMusic: firstIndex}});
                   
         }
     }
    

    Besides, if I change it, for testing purpose, as follow pageStack.push({item: "qrc:/qml/musicPlayer/SongController.qml"});, it doesn't work either.

    Can you advise me? Thank you.

    A 1 Reply Last reply 16 Jul 2018, 05:15
    0
    • D davidino
      15 Jul 2018, 18:16

      Goodmonring,
      I've create a stackView, as shown in the code below. If I simply pass the qrc link it works perfectly, but when I try to load some properties together with the page, it failed. I tried to see the documentation and examples but to me it looks that everything is ok.

      import QtQuick 2.6
      import QtQuick.Controls 2.0
      import "imageView/."            // QTBUG-34418, singletons require explicit import to load qmldir file
      
      ApplicationWindow {
      
          readonly property alias pageStack: stackView
      
          readonly property int playerPage: 0
          readonly property int songControllerPage: 1
      
          id: app
          visible: true
          width: 1368
          height: 768
          color: Style.windowBackground
      
          StackView {
              id: stackView
              anchors.fill: parent
              initialItem: Qt.resolvedUrl("qrc:/qml/musicPlayer/PlayerPage.qml"); 
          }
      
          onClosing: {
              if (Qt.platform.os == "android") {
                  if (stackView.depth > 1) {
                      close.accepted = false
                      stackView.pop()
                  }
              }
          }
      }
      

      The method used in PlayerPage.qml to change page is the following:

      MouseArea {
                 id: playArea
                 anchors.fill: parent
                 onReleased:
                 {
                           pageStack.push({item: "qrc:/qml/musicPlayer/SongController.qml",
                           properties: {currentIndex: index, items: objects firstIndexMusic: firstIndex}});
                     
           }
       }
      

      Besides, if I change it, for testing purpose, as follow pageStack.push({item: "qrc:/qml/musicPlayer/SongController.qml"});, it doesn't work either.

      Can you advise me? Thank you.

      A Offline
      A Offline
      ambershark
      wrote on 16 Jul 2018, 05:15 last edited by
      #2

      @davidino What does it do? Does it give an error? Can you write a quick qml file or 2 that can be run in qmlscene to duplicate the problem and share that here?

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      1
      • D Offline
        D Offline
        davidino
        wrote on 16 Jul 2018, 18:53 last edited by davidino
        #3

        Hello @ambershark, thank you for your answer.
        I apologize, I forgot to write the most important thing. The error that I get is QML StackView: push: nothing to push.

        To summarize, pageStack.push("qrc:/qml/musicPlayer/SongController.qml"); works.
        Instead, pageStack.push({item: "qrc:/qml/musicPlayer/SongController.qml"}); or pageStack.push({item: "qrc:/qml/musicPlayer/SongController.qml",
        properties: {currentIndex: index, items: objects firstIndexMusic: firstIndex}});
        don't work.

        If it can help, this is the first part of SongController.qml:

        Item
        {
            id: songController
        
            property FolderListModel items
            property alias mediaPlayer: playMusic
            property int currentIndex
            property int firstIndexMusic
        .......
        

        Regarding the qmlscene request, since I never used it I need more time for studying it, in the meantime I hope my answer can help to figure out the problem.
        Thank you.

        P.S.
        My Qt version is 5.11.0

        1 Reply Last reply
        0
        • D Offline
          D Offline
          davidino
          wrote on 16 Jul 2018, 20:11 last edited by
          #4

          The problem has been solved using the following module version:
          import QtQuick.Controls 1.4 instead of import QtQuick.Controls 2.0.
          I wonder what the difference is...

          P E 2 Replies Last reply 16 Jul 2018, 20:15
          2
          • D davidino
            16 Jul 2018, 20:11

            The problem has been solved using the following module version:
            import QtQuick.Controls 1.4 instead of import QtQuick.Controls 2.0.
            I wonder what the difference is...

            P Offline
            P Offline
            Pablo J. Rogina
            wrote on 16 Jul 2018, 20:15 last edited by
            #5

            @davidino if your issue is solved, please don't forget to mark your post as such. Thanks

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • D davidino
              16 Jul 2018, 20:11

              The problem has been solved using the following module version:
              import QtQuick.Controls 1.4 instead of import QtQuick.Controls 2.0.
              I wonder what the difference is...

              E Offline
              E Offline
              ekkescorner
              Qt Champions 2016
              wrote on 17 Jul 2018, 08:53 last edited by
              #6

              @davidino said in Passing parameters with StackView:

              The problem has been solved using the following module version:
              import QtQuick.Controls 1.4 instead of import QtQuick.Controls 2.0.
              I wonder what the difference is...

              these are two different StackView Controls
              Controls 1.x: http://doc.qt.io/qt-5/qml-qtquick-controls-stackview.html
              Controls 2.x: https://doc.qt.io/qt-5.11/qml-qtquick-controls2-stackview.html

              read more about QtQuickControls 2 here: https://doc.qt.io/Qt-5/qtquickcontrols2-index.html

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

              1 Reply Last reply
              2
              • D Offline
                D Offline
                davidino
                wrote on 17 Jul 2018, 19:19 last edited by davidino
                #7

                Hello, thank you to all.
                At last, it works with module QtQuick.Controls 2.0, too.

                pageStack.push("qrc:/qml/musicPlayer/SongController.qml",
                {currentIndex: index, items: objects, firstIndexMusic: firstIndex});

                1 Reply Last reply
                1

                1/7

                15 Jul 2018, 18:16

                • Login

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