小编tim*_*tim的帖子

在QListWidget上QTest :: mouseClick的问题

我正在尝试使用QTest进行一些测试.我有一个QListWidget,我想点击它来获取选择.但点击后,没有选择任何内容.有没有人有任何想法?

这是我的测试课

void TestGui::List() {
    TestDialog dlg;
    dlg.show ();

    // Click on the centre of the second object
    QListWidget *list = dlg.ListWidget ();
    QListWidgetItem *item = list->item ( 1 );
    QRect rect = list->visualItemRect ( item );
    QTest::mouseClick ( list, Qt::LeftButton, 0, rect.center() );

    // Check if something was selected
    QCOMPARE ( list->currentRow (), 1 );
    QVERIFY ( list->currentItem () != NULL );
    QCOMPARE ( list->currentItem ()->text (), QString ( "Two" ) );
}
Run Code Online (Sandbox Code Playgroud)

以下是测试类

class TestGui: public QObject { …
Run Code Online (Sandbox Code Playgroud)

qtestlib

7
推荐指数
1
解决办法
1188
查看次数

标签 统计

qtestlib ×1