Compiler complains about calling base class function 'index(int,int)' in class inherited from QAbstractTableModel
-
Using Qt 5.15.13 and g++ compiler version 13.3.0 on Ubuntu 24.04.3:
In the implementation of the
setData()override I want to emit the signaldataChangedover a range of indexes. I have this code which won't compile:QModelIndex idx_topleft = index(0,0); QModelIndex idx_bottomright = index(rowCount()-1,columnCount()-1);The error I am shown is this:
error: no match for call to ‘(const QModelIndex) (int, int)’which is strange because
index()is a public member function of the base classQAbstractTableModel.However, if I call it this way:
QModelIndex idx_topleft = this->index(0,0); QModelIndex idx_bottomright = this->index(rowCount()-1,columnCount()-1);or if I fully qualify the call with the base class name, it works.
Does this have something to do with "Koenig lookup" rules? -
Using Qt 5.15.13 and g++ compiler version 13.3.0 on Ubuntu 24.04.3:
In the implementation of the
setData()override I want to emit the signaldataChangedover a range of indexes. I have this code which won't compile:QModelIndex idx_topleft = index(0,0); QModelIndex idx_bottomright = index(rowCount()-1,columnCount()-1);The error I am shown is this:
error: no match for call to ‘(const QModelIndex) (int, int)’which is strange because
index()is a public member function of the base classQAbstractTableModel.However, if I call it this way:
QModelIndex idx_topleft = this->index(0,0); QModelIndex idx_bottomright = this->index(rowCount()-1,columnCount()-1);or if I fully qualify the call with the base class name, it works.
Does this have something to do with "Koenig lookup" rules?@Robert-Hairgrove
If this is inside your override defined assetData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)then obviously you have a local variable namedindex.Either use the "full qualification" of
this->indexto disambiguate or rename yourindexformal parameter in the declaration. -
@Bonnie Thanks -- yes, that was exactly the problem! :)
The Qt Creator wizard "helpfully" set up the parameters like this when I added the class. When I changed the parameter name, it works without qualifying the function call.
Marking this now as "solved".
-
R Robert Hairgrove has marked this topic as solved on