Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Compiler complains about calling base class function 'index(int,int)' in class inherited from QAbstractTableModel

Compiler complains about calling base class function 'index(int,int)' in class inherited from QAbstractTableModel

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on last edited by
    #1

    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 signal dataChanged over 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 class QAbstractTableModel.

    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?

    JonBJ 1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by
      #2

      You probably have const QModelIndex &index in the parameters of setData(), right?

      R 1 Reply Last reply
      1
      • R Robert Hairgrove

        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 signal dataChanged over 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 class QAbstractTableModel.

        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?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Robert-Hairgrove
        If this is inside your override defined as setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) then obviously you have a local variable named index.

        Either use the "full qualification" of this->index to disambiguate or rename your index formal parameter in the declaration.

        1 Reply Last reply
        1
        • B Bonnie

          You probably have const QModelIndex &index in the parameters of setData(), right?

          R Offline
          R Offline
          Robert Hairgrove
          wrote on last edited by
          #4

          @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".

          1 Reply Last reply
          0
          • R Robert Hairgrove has marked this topic as solved on

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved