Originally Posted by
ars
Hello,
I looked into Qt 4.7.3 sources and there createIndex() is defined as an inline method in the header file under src/corelib/kernel/qabstractitemmodel.h. I assume this did not change in more recent versions (Qt 5.x).
You are right, got it thanks. Here it is:
inline QModelIndex QAbstractItemModel::createIndex(int arow, int acolumn, void *adata) const
{ return QModelIndex(arow, acolumn, adata, this); }
To copy to clipboard, switch view to plain text mode
And then I wonder what this QModelIndex function is, and it is defined in the same file:
: r(other.r), c(other.c), p(other.p), m(other.m) {}
inline QModelIndex() : r(-1), c(-1), p(0), m(0) {}
inline QModelIndex(const QModelIndex &other)
: r(other.r), c(other.c), p(other.p), m(other.m) {}
To copy to clipboard, switch view to plain text mode
And I don't really understand what it is doing (can anywone explain? (e.g., p(other.p)--what is that?) ).
Perhaps I should have been more clear about my goal: I am asking because the implementation of index within QAbstractTableModel is:
{
return hasIndex
(row, column, parent
) ? createIndex
(row, column,
0) : QModelIndex();
}
QModelIndex QAbstractTableModel::index(int row, int column, const QModelIndex &parent) const
{
return hasIndex(row, column, parent) ? createIndex(row, column, 0) : QModelIndex();
}
To copy to clipboard, switch view to plain text mode
And I am confused about the third input to createIndex: why is it just 0 when the corresponding item has an index? Why doesn't it return the data item using something like an internalPointer? That is, I am used to sending an actual data item as the third input to createIndex (as in the simpletreemodel example that comes with Qt). (In C++ I think you send a pointer as the third item, but even so why send the integer 0?).
Bookmarks