QAbstractItemModelTester Class▲
-
Header: QAbstractItemModelTester
-
Since: Qt 5.11
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Test)
target_link_libraries(mytarget PRIVATE Qt6::Test)
-
qmake: QT += testlib
-
Inherits: https://
Detailed Description▲
The https:// class is a utility class to test item models.
When implementing an item model (that is, a concrete https:// subclass) one must abide to a very strict set of rules that ensure consistency for users of the model (views, proxy models, and so on).
For instance, for a given index, a model's reimplementation of https://() must be consistent with the values returned by https://() and https://().
https:// helps catching the most common errors in custom item model classes. By performing a series of tests, it will try to check that the model status is consistent at all times. The tests will be repeated automatically every time the model is modified.
https:// employs non-destructive tests, which typically consist in reading data and metadata out of a given item model. https:// will also attempt illegal modifications of the model. In models which are properly implemented, such attempts should be rejected, and no data should be changed as a consequence.
Usage▲
Using https:// is straightforward. In a https:// it is sufficient to create an instance, passing the model that needs to be tested to the constructor:
MyModel *modelToBeTested = ...;
auto tester = new QAbstractItemModelTester(modelToBeTested);https:// will report testing failures through the Qt Test logging mechanisms.
It is also possible to use https:// outside of a test case. For instance, it may be useful to test an item model used by an application without the need of building an explicit unit test for such a model (which might be challenging). In order to use https:// outside of a test case, pass one of the QAbstractItemModelTester::FailureReportingMode enumerators to its constructor, therefore specifying how failures should be logged.
https:// may also report additional debugging information as logging messages under the qt.modeltest logging category. Such debug logging is disabled by default; refer to the https:// documentation to learn how to enable it.
While https:// is a valid help for development and testing of custom item models, it does not (and cannot) catch all possible problems in https:// subclasses. Notably, it will never perform meaningful destructive testing of a model, which must be therefore tested separately.
See Also▲
See also https://, QAbstractItemModel
Member Type Documentation▲
enum QAbstractItemModelTester::FailureReportingMode▲
This enumeration specifies how https:// should report a failure when it tests a https:// subclass.
|
Constant |
Value |
Description |
|---|---|---|
|
https://::FailureReportingMode::QtTest |
0 |
The failures will be reported as https:// test failures. |
|
https://::FailureReportingMode::Warning |
1 |
The failures will be reported as warning messages in the qt.modeltest logging category. |
|
https://::FailureReportingMode::Fatal |
2 |
A failure will cause immediate and abnormal program termination. The reason for the failure will be reported using qFatal(). |
Member Function Documentation▲
QAbstractItemModelTester::QAbstractItemModelTester(QAbstractItemModel *model, QObject *parent = nullptr)▲
Creates a model tester instance, with the given parent, that will test the model model.
QAbstractItemModelTester::QAbstractItemModelTester(QAbstractItemModel *model, QAbstractItemModelTester::FailureReportingMode mode, QObject *parent = nullptr)▲
Creates a model tester instance, with the given parent, that will test the model model, using the specified mode to report test failures.
See Also▲
See also https://
QAbstractItemModelTester::FailureReportingMode QAbstractItemModelTester::failureReportingMode() const▲
QAbstractItemModel *QAbstractItemModelTester::model() const▲
Returns the model that this instance is testing.


