使用 modeltest 进行 QAbstractItem 模型测试
我正在寻找一个关于如何使用 modeltest 来测试基于 QAbstractItemModel 的模型的好教程。我不知道如何解释显示的调试消息。
此外,我在配置模型测试项目以与 QtCreator 中的应用程序一起使用时遇到问题。包含 .pri/.pro 不起作用。我收到一条错误消息“没有法师目标规则..”。修复 modeltest/modeltest.pro 文件中的路径后,它开始编译。但我得到了这个奇怪的断言
断言:文件 c:\ndk_buildrepos\qt-desktop\src\testlib\qtestlog.cpp 中的“QTest::testLogger”,第 232 行
任何想法为什么会发生这种情况?
我的 modeltest 文件夹位于我的项目内。我在 *.pro 文件末尾添加了以下行
include(modeltest/modeltest.pri)
modeltest.pri 文件包含以下内容
load(qttest_p4)
SOURCES += modeltest/modeltest.cpp modeltest/dynamictreemodel.cpp
HEADERS += modeltest/modeltest.h modeltest/dynamictreemodel.h
我修改了代码以使用 modeltest 这种方式
model = new TasksModel(this);
new ModelTest(model, this);
ui->treeView->setModel(model);
TasksModel 是我对 QAbstractItemModel 模型的实现。 ui->treeView是显示数据的widget。
将模型测试与我的应用程序集成时没有进行其他修改。
Qt版本是4.7。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这听起来有点过分 - 但事实上,这正是 ModelChecker 开发人员希望您做的事情;)当您击中其中一个断言时,请转到代码中击中该断言的位置并阅读以下注释:与它一起写的。整件事都得到了非常多的评论,并描述了问题所在以及可能的原因。如果您通过 GUI 调试器(例如 KDevelop、Qt Creator 或 Visual Studio 中包含的调试器)运行应用程序,那么这是迄今为止最容易做到的。
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.
您收到此错误的原因是因为您实际上并未在正确的 QTestLib 测试用例中使用 ModelTest。如果您查看 /tests/auto/modeltest (您可能首先在其中获得了 modeltest 类),您可以了解如何使用 ModelTest 正确构建测试用例。
The reason you are getting this error is because you aren't actually using the ModelTest inside a proper QTestLib test case. If you take a look at /tests/auto/modeltest (where you presumably got the modeltest class in the first place), you can see how to properly construct a test case using the ModelTest.