Search code examples
c++qtmodel-view-controllerqabstractitemmodelqmodelindex

Qt QModelIndex::sibling return parent QModelIndex


Having a QAbstractItemModel grModel and calling:

QModelIndex grSrcPrtIdx = grModel.index( 1, 0 );
QModelIndex grSrcIdx1   = grSrcPrtIdx.sibling( 1, 0 );
QModelIndex grSrcIdx2   = grModel.index( 1, 0, grSrcPrtIdx )  

Results in: grSrcPrtIdx == grSrcIdx1 with grSrcPrtIdx containing the data expected for grSrcPrtIdx while grSrcIdx2 contains the expected data for the sibling. My expectation is that grSrcIdx1 == grSrcIdx2.

It seems that the sibling function provides a defaut implementation (or something similar?).

What might be the cause that the sibiling function does not deliver the siblings QModelIndex? Did I miss to implement a function of the QAbstractItemModel?

Qt version used is Qt 5.10.0 (MinGw).


Solution

  • The comments of G.M. and aatwo are the helping ones.