Passing parameters with StackView



  • 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.


  • Moderators

    @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?



  • 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



  • 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...



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


  • Qt Champions 2016

    @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



  • 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});


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.