Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Model Test: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Convert ExpressionEngine links)
(Image & formatting.)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
 


'''English''' [[Model_Test_Spanish|Spanish]]
'''English''' [[Model_Test_Spanish|Spanish]]
Line 9: Line 9:
ModelTest continuously checks a model as it changes, helping to verify the state and catching many common errors the moment they show up.
ModelTest continuously checks a model as it changes, helping to verify the state and catching many common errors the moment they show up.


[[Image:http://developer.qt.nokia.com/uploads/image_upload/Modeltest.png|http://developer.qt.nokia.com/uploads/image_upload/Modeltest.png]]
[[Image:Modeltest.png]]


Some of the conditions caught include:
Some of the conditions caught include:
Line 23: Line 23:
To use the model test do the following:
To use the model test do the following:


# Include the pri file at the end of your project pro file using the include() command like so:
1. Include the pri file at the end of your project pro file using the include() command like so:
''include(../path/to/dir/modeltest.pri)''
''include(../path/to/dir/modeltest.pri)''


# Then in your source include "modeltest.h" and instantiate ModelTest with your model so the test can live for the lifetime of your model. For example:
2. Then in your source include "modeltest.h" and instantiate ModelTest with your model so the test can live for the lifetime of your model. For example:
<code>#include <modeltest.h>
<code>#include <modeltest.h>


Line 32: Line 32:
new ModelTest(model, this);</code>
new ModelTest(model, this);</code>


# That is it. When the test finds a problem it will assert. modeltest.cpp contains some hints on how to fix problems that the test finds.
3. That is it. When the test finds a problem it will assert. modeltest.cpp contains some hints on how to fix problems that the test finds.


The source can be found [http://qt.gitorious.org/qt/qt/trees/4.7/tests/auto/modeltest here]
The source can be found [http://code.qt.io/cgit/qt/qt.git/tree/tests/auto/modeltest here]

Revision as of 09:08, 25 March 2015


English Spanish

Model Test

ModelTest provides a way to check for common errors in implementations of QAbstractItemModel.

ModelTest continuously checks a model as it changes, helping to verify the state and catching many common errors the moment they show up.

Modeltest.png

Some of the conditions caught include:

  • Verifying X number of rows have been inserted in the correct place after the signal rowsAboutToBeInserted() says X rows will be inserted.
  • The parent of the first index of the first row is a QModelIndex()
  • Calling index() twice in a row with the same values will return the same QModelIndex
  • If rowCount() says there are X number of rows, model test will verify that is true.
  • Many possible off by one bugs
  • hasChildren() returns true if rowCount() is greater then zero.
  • and many more…

To use the model test do the following:

1. Include the pri file at the end of your project pro file using the include() command like so: include(../path/to/dir/modeltest.pri)

2. Then in your source include "modeltest.h" and instantiate ModelTest with your model so the test can live for the lifetime of your model. For example:

#include <modeltest.h>

QDirModel *model = new QDirModel(this);
new ModelTest(model, this);

3. That is it. When the test finds a problem it will assert. modeltest.cpp contains some hints on how to fix problems that the test finds.

The source can be found here