Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. model view rowCount
Qt 6.12 LTS is out! See what's new in the release blog

model view rowCount

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.2k Views 2 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.
  • J Offline
    J Offline
    jss193
    wrote on last edited by
    #1

    Hello!

    I am trying to understand the way in which Table Models work by doing the tutorials provided by Qt, I am facing the problem that I am not able to understand the following code lines:

    int rowCount(const QModelIndex &parent = QModelIndex())const override;
    

    Your are declaring a method (rowCount) and passing it a const of type QModelIndex pointing to a memory address (&parent) and why is equal to QModelIndex? for me this makes no sense, why pass a memory address to (neither know what parent really means or where it is, I guess it is the parent class).

    Can someone (please), explain me this code?

    Thank you!

    M 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      parent if not given when calling the function will contain an invalid index.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • J jss193

        Hello!

        I am trying to understand the way in which Table Models work by doing the tutorials provided by Qt, I am facing the problem that I am not able to understand the following code lines:

        int rowCount(const QModelIndex &parent = QModelIndex())const override;
        

        Your are declaring a method (rowCount) and passing it a const of type QModelIndex pointing to a memory address (&parent) and why is equal to QModelIndex? for me this makes no sense, why pass a memory address to (neither know what parent really means or where it is, I guess it is the parent class).

        Can someone (please), explain me this code?

        Thank you!

        M Offline
        M Offline
        mpergand
        wrote on last edited by
        #3

        @jss193 said in model view rowCount:

        and passing it a const of type QModelIndex pointing to a memory address (&parent)

        This not an adress, it's a reference.
        rowCount is a abstract method you must implement in your QAbstractTableModel subclass.
        The parent ModelIndex is only relevant in a TreeView and not use in a TableView.

        1 Reply Last reply
        0

        • Login

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