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. model view rowCount
Qt 6.11 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 724 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 Extensions
        • Unsolved