Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions 027_tool.qabstractitemmodeltester.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Use QAbstractItemModelTester for Custom Models

## Goals
Detect/Avoid a certain set of errors in subclasses of QAbstractItemModel.

## Description
QAbstractItemModelTester can be used to detect common errors in the implementation of models based on QAbstractItemModel with very little effort and even before they appear in the form of a visible bug.

## Environment
Qt

## Platform
All

## Implementation effort
Very minimal

## Applicability
- When implementing new models
- As part of test suites
- In debug sessions

## Caveats
Citing the [documentation](https://doc.qt.io/qt-5/qabstractitemmodeltester.html):

> While QAbstractItemModelTester is a valid help for development and testing of custom item models, it does not (and cannot) catch all possible problems in QAbstractItemModel subclasses. Notably, it will never perform meaningful destructive testing of a model, which must be therefore tested separately.

## See also

## Implementation hints
QAbstractItemModelTester can be used in two ways:

In unit tests
Directly in the running application (introduces testlib-dependency). Should be disabled for release builds. At least QAbstractItemModelTester::FailureReportingMode::Fatal should not be used in release builds
Both ways are described in the [documentation](https://doc.qt.io/qt-5/qabstractitemmodeltester.html)