Search code examples
qttestingqt4qt-creatorqabstractitemmodel

QAbstractItemModel testing using modeltest


I'm looking for a good tutorial on how to use modeltest to test models based on QAbstractItemModel. I don't know how to interpret debug messages that are displayed.

Also I'm having trouble configuring modeltest project to work with my app in QtCreator. Including the .pri/.pro doesn't work. I get an error saying "No rule to mage target ..". After fixing paths in modeltest/modeltest.pro file it starts to compile. But i get this wierd assertion

ASSERT: "QTest::testLogger" in file c:\ndk_buildrepos\qt-desktop\src\testlib\qtestlog.cpp, line 232

Any ideas why this happens ?


My modeltest folder is located inside my project. I added following line at the end of my *.pro file

include(modeltest/modeltest.pri)

The modeltest.pri file contains the following

load(qttest_p4)
SOURCES         += modeltest/modeltest.cpp modeltest/dynamictreemodel.cpp 
HEADERS         += modeltest/modeltest.h modeltest/dynamictreemodel.h

I modified my code to use modeltest this way

model = new TasksModel(this);
new ModelTest(model, this);
ui->treeView->setModel(model);

TasksModel is my implementation of QAbstractItemModel model. ui->treeView is the widget that displays data.

No other modifications where made while integrating modeltest with my app.

Qt version is 4.7.


Solution

  • This will sound a little overgeeky - but it is, in fact, what the ModelChecker dev intended for you to do ;) When you hit one of the asserts, go to the point in the code where it is hit and read the comments which are written along with it. The entire thing is extremely heavily commented, and describes what is breaking and likely reasons why. This is by far easiest to do if you run your app through a GUI debugger, such as that included in for example KDevelop, Qt Creator or Visual Studio.