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. Do i have to check QModelIndex::isValid() in overriden methods of QAbstractListModel
Forum Updated to NodeBB v4.3 + New Features

Do i have to check QModelIndex::isValid() in overriden methods of QAbstractListModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 140 Views
  • 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.
  • Y Offline
    Y Offline
    Youda0008
    wrote on last edited by
    #1

    I'm writing a custom item model implementation - i have a class that inherits from QAbstractListModel and overrides

    • Qt::ItemFlags flags( const QModelIndex & index )
    • QVariant data( const QModelIndex & index, int role )
    • bool setData( const QModelIndex & index, const QVariant & value, int role )
    • QMimeData * mimeData( const QModelIndexList & indexes )
    • ... and more ...

    In these functions named above, do i have to check if the model indexes are valid, or can i count with the framework always supplying me valid ones? I haven't seen this being specified anywhere in the documentation.

    JonBJ 1 Reply Last reply
    0
    • Y Youda0008

      I'm writing a custom item model implementation - i have a class that inherits from QAbstractListModel and overrides

      • Qt::ItemFlags flags( const QModelIndex & index )
      • QVariant data( const QModelIndex & index, int role )
      • bool setData( const QModelIndex & index, const QVariant & value, int role )
      • QMimeData * mimeData( const QModelIndexList & indexes )
      • ... and more ...

      In these functions named above, do i have to check if the model indexes are valid, or can i count with the framework always supplying me valid ones? I haven't seen this being specified anywhere in the documentation.

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

      @Youda0008
      Most code does/should check. If you look at the base implementations in QAbstractListModel I think you will see they do check isValid()? Or at least all derived classes? Since you are overriding them, or doing your own stuff before you call them, I would check. It's only an if. Or at least check if compiling for debug?

      1 Reply Last reply
      1

      • Login

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