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. stackView.push() does not recognize item
QtWS25 Last Chance

stackView.push() does not recognize item

Scheduled Pinned Locked Moved QML and Qt Quick
stackview
2 Posts 2 Posters 1.1k 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
    dhb285
    wrote on 19 Nov 2016, 14:18 last edited by
    #1

    I am failing to pass an item to stackView.push(). i have looked at the following and tried all the described options, but all failed:

    http://doc.qt.io/qt-5/qml-qtquick-controls-stackview.html

    Here are my simple files:

    QmlBackbone.qml:

    import QtQuick 2.5
    import QtQuick.Controls 1.4
    import QtQuick.Dialogs 1.2
    
    ApplicationWindow {
        visible: true
        width: 800
        height: 480
        StackView{
            id: stackView
            width: parent.width
            height: parent.height
            initialItem: MainView {}
        }
    }
    

    MainView.qml:

    import QtQuick 2.5
    import QtQuick.Controls 1.4
    import QtQuick.Dialogs 1.2
    
    Component {
        id: mainView
    
        Column {
            spacing: 2
            width: parent.width
            height: parent.height
            Rectangle { color: "red"; width: parent.width; height: parent.height/2
                    Label {
                        width: parent.width
                        wrapMode: Label.Wrap
                        horizontalAlignment: Qt.AlignHCenter
                        text: "Testing."
                    }
            }
            Rectangle { color: "green"; width: parent.width; height: parent.height/2
                Label {
                    width: parent.width
                    wrapMode: Label.Wrap
                    horizontalAlignment: Qt.AlignHCenter
                    text: "Settings"
                }
                MouseArea{
                    anchors.fill: parent
                    onClicked: stackView.push(settingView)
                }
            }
        }
    }
    

    SettingView.qml:

    import QtQuick 2.5
    import QtQuick.Controls 1.4
    import QtQuick.Dialogs 1.2
    
    Component {
        id: settingView
    //    width: parent.width
    //    height: parent.height
    
        Column {
            spacing: 2
            width: parent.width
            height: parent.height
            Rectangle { color: "red"; width: parent.width; height: parent.height/4
                    Label {
                        width: parent.width
                        wrapMode: Label.Wrap
                        horizontalAlignment: Qt.AlignHCenter
                        text: "Height."
                    }
            }
            Rectangle { color: "green"; width: parent.width; height: parent.height/4
                Label {
                    width: parent.width
                    wrapMode: Label.Wrap
                    horizontalAlignment: Qt.AlignHCenter
                    text: "Plot."
                }
            }
            Rectangle { color: "blue"; width: parent.width; height: parent.height/4
                Label {
                    width: parent.width
                    wrapMode: Label.Wrap
                    horizontalAlignment: Qt.AlignHCenter
                    text: "Note."
                }
            }
            Rectangle { color: "orange"; width: parent.width; height: parent.height/4
                Label {
                    width: parent.width
                    wrapMode: Label.Wrap
                    horizontalAlignment: Qt.AlignHCenter
                    text: "Back."
                }
            }
    
        }
    }
    

    The problem is in the onClicked method of the Settings rectangle of the MainView.
    How is that possible and how to solve that problem? All files are in the same folder. I have tried all methods described in the link, I have tried putting the url within QUrl() method, and I have tried methods found elsewhere on the Internet. All of them failed.

    Incidentally, I cannot see any error messages at all neither within QTCreater, which I use to write the qml files, nor in Eclipse (PyDev), which I use to write the PyQt surrounding code. Why does that happen and how to fix that?

    Thank you in advance.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mario84
      wrote on 24 Nov 2016, 19:50 last edited by Mario84
      #2

      Hi @dhb285,

      the problem is, that you do not instantiate your SettingView.

      To solve it, you should make 2 little changes:

      1. Remove the following line from SettingView.qml:
          id: settingView
      
      1. Add an instance of SettingView to your StackView (as you did with MainView):
          StackView{
              ...
              initialItem: MainView {}
              SettingView { id: settingView }
              ...
      

      But I cannot tell why you can't see errors in QtCreator, when I run your code I get the following message in the Application Output:

      qrc:/MainView.qml:29: ReferenceError: settingView is not defined
      
      1 Reply Last reply
      0

      1/2

      19 Nov 2016, 14:18

      • Login

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