如何使用 QTest 测试 QTableView 版本
How test QTableView edition with QTest?
我想用QTest模拟QTableView单元格的版本。
我尝试了不同的方法,但没有任何成功:
qtableview->show();
/* I think that in my unit test I should no need
that, could you confirm ? */
QModelIndex modelIndex = qtableview->model()->index(1,1);
//I have tested that modelIndex is valid and that I retrieved expected data
/*First try: set the currentIndex on modelIndex
thinking that keyClicks on qtableview will work
on selected element of the tableview*/
qtableview->setCurrentIndex(modelIndex );
QTest::KeyClicks(qtableview,“Hello Word”);
QCOMPARE->index(1,1).data(), “Hello World”); // —> FAILED
/*Second approach
Get the cell widget*/
QWidget * qwidget = qtableview->indexWidget( modelIndex );
//—> No test since the qwidget is NULL… why ?
/*Third approach
Get the cell widget through the delegate*/
QWidget * qwidget =
qtableview->itemDelegate( modelIndex )->createEditor(qtableview,
QStyleOptionViewItem(),
modelIndex );
QTest::KeyClicks(qwidget ,“Hello Word”);
QCOMPARE->index(1,1).data(), “Hello World”); // —> FAILED
我也添加了三个 proache 没有任何成功
QTest::mouseDClick(qtableview)
QTest::KeyClicks(qtableview,“Hello Word”);
感谢您的帮助。
我认为您需要在显示小部件后处理事件。如果QListView被隐藏,它可能不会做任何事情(因为它应该这样做!看看qWaitForWindowDisplay(qtableview)是否可以解决问题。如果这不起作用,请通过调用 QCoreApplication::p rocessEvents() 直接运行事件循环。看看qWaitForWindowShow,无论如何它都可能旋转一个事件循环。
相关文章:
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 导入库可以跨dll版本工作吗
- QTableView:endMoveRows在模型中重置水平页眉大小
- 在调用FreeLibrary后,释放动态链接到具有相同版本的CRT堆的DLL的内存
- 在clang++预处理器中确定gcc工具链版本
- 码头化的C++应用程序是否向后兼容早期的内核版本
- 将QIcon添加到QTableView单元格
- 不同的Visual Studio版本中缺少.dll
- 用符号版本替换对函数的所有调用
- luaL_dofile在已知良好的字节码上失败,可以使用未编译的版本
- 正在解码MSVC 32位版本的程序集(作业).没有手术做什么
- 我需要分发哪些版本的可再分发文件
- CV_OCL_RUN宏如何在OpenCV(版本3.4.5)的goodFeaturesToTrack实现中工作?
- 在运行时读取 libstdc++ 版本
- 如何声明一个可以在整个程序中使用的全局 2d 3d 4d .. 数组(堆版本)变量?
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- Vulkan SDK 版本 1.1.85.0 在 Kubuntu 18.10 上链接
- 如何正确实现与基类不同的版本?
- 如何在QTableView中排序和更改日期格式
- 如何使用 QTest 测试 QTableView 版本