Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-26536

Warning "QQuickItem::stackBefore: Cannot stack before" with trivial C++ model and Qml delegate

    XMLWordPrintable

Details

    Description

      The following minimal code triggers a warning inside QQuickItem::stackBefore although I cannot see anything wrong in my code.

      If the model's content is set before the repeater is created it works, a model reset must be triggered to see the problem (this is what I use the qml timer for).

      The symptom for the warning is that "this == sibling".

      Complete project is attached.

      #include <QtGui>
      #include <QtCore>
      #include <QtQuick>
      
      class MyModel : public QAbstractListModel
      {
        Q_OBJECT
      
      public:
      
        MyModel(QObject *parent = 0) : QAbstractListModel(parent)
        {
          QHash<int, QByteArray> roleNames;
          roleNames[Qt::UserRole + 1] = "text";
          setRoleNames(roleNames);
        }
      
        int rowCount(const QModelIndex &) const { return m_data.size(); }
        int columnCount(const QModelIndex &) const { return 1; }
      
        Q_INVOKABLE void setStuff()
        {
          QStringList s;
          s << "One" << "two" << "three";
          beginResetModel();
          m_data = s;
          endResetModel();
        }
      
        QVariant data(const QModelIndex &index, int) const
        {
          return m_data.at(index.row());
        }
      
      private:
      
        QStringList m_data;
      };
      
      int main(int argc, char *argv[])
      {
        QGuiApplication app(argc, argv);
      
        QQuickView viewer;
        MyModel m;
        viewer.rootContext()->setContextProperty("theModel", &m);
        viewer.setSource(QUrl("qrc:/qml/untitled3/main.qml"));
        viewer.show();
      
        return app.exec();
      }
      
      #include "main.moc"
      
      import QtQuick 2.0
      
      Rectangle {
        width: 360
        height: 360
      
        Column {
          anchors.fill: parent
      
          Repeater {
            id: repeater
            model: theModel
            delegate: Row {
              Text { text: "Yeah " + model.text }
            }
          }
        }
      
        Timer {
          // used to trigger model reset
          interval: 1000
          onTriggered: theModel.setStuff()
          running: true
          repeat: true
        }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            denexter Andrew den Exter (closed Nokia identity) (Inactive)
            njeisecke Nils Jeisecke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes