Do i have to check QModelIndex::isValid() in overriden methods of QAbstractListModel
-
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.
-
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.
@Youda0008
Most code does/should check. If you look at the base implementations inQAbstractListModel
I think you will see they do checkisValid()
? 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 anif
. Or at least check if compiling for debug?