简体   繁体   English

如何使用qtestlib测试完整的Qt5 GUI?

[英]How can I test a full Qt5 GUI using qtestlib?

Using qtestlib with my Qt5 C++ widgets application, how can I test my full GUI ? 在我的Qt5 C ++小部件应用程序中使用qtestlib ,如何测试完整的GUI

In the documentation for qtestlib , it is explained how I could test an indivdual QWidget by simulating keypresses etc, however this seems impossible to do for a full UI, because the individual widgets of my UI are hidden inside the automatically generated ui_XXX.h file. qtestlib文档中,说明了如何通过模拟按键等来测试单个QWidget ,但是对于完整的UI似乎无法做到,因为UI的各个小部件都隐藏在自动生成的 ui_XXX.h文件中。

So how would I go about doing this? 那我该怎么做呢?

In your ui files you can give names to the widgets. 在您的ui文件中,您可以为小部件命名。 You can then search through the children from your toplevel widget. 然后,您可以从顶级窗口小部件中搜索子级。

For example to test that a Label reflects the characters entered into a LineEdit you could use: 例如,要测试“标签”是否反映了输入到LineEdit中的字符,可以使用:

MainWindow win;

QLineEdit *edit = win.findChild<QLineEdit *>("myLineEdit");
QTest::sendKeys(edit, "Example");

QLabel *label = win.findChild<QLabel *>("myLabel");
QCOMPARE(label->text(), "Example");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM