5

It is more concrete version of this question.

I want to report to the view that I'm going to insert some rows to my model. There are two ways to call beginInsertRows:

beginInsertRows(QModelIndex(), first, last)

and

beginInsertRows(createIndex(-1,-1), first, last)

There is a difference: in the 2nd variant QModelIndex will store pointer to our model inside itself. And in Qml internals:

void QQuickVisualDataModel::_q_rowsInserted(const QModelIndex &parent, int begin, int end)
{
    Q_D(QQuickVisualDataModel);
    qDebug() << "d->m_adaptorModel.rootIndex = " << d->m_adaptorModel.rootIndex;
    if (parent == d->m_adaptorModel.rootIndex)
        _q_itemsInserted(begin, end - begin + 1);
}

the body of if statement will not be executed because it seems that rootIndex always does not store pointer to the model (i.e. it stores NULL instead)

I have created test Qt5 application

So, my question is: Is it bug or feature? Have somebody tried this buggy invocation before me?

Community
  • 1
  • 1
Kakadu
  • 2,837
  • 19
  • 29
  • Perhaps it is a bug. I'd suggest using index() for this use case http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#index – MartinJ Mar 28 '13 at 11:44
  • Yeah, I have added a condition `if (row==-1||column==-1) return QModelIndex() else return createIndex(row,column)` and it helps. But it does not close my question. – Kakadu Mar 28 '13 at 21:37

0 Answers0