您可以使用QTimer
QTest ::keyClick()。
如果您QMessgeBox
的 ' 指针是msgBox
,在QTimer
'timeout()
插槽中,
QTest::keyClick( msgBox, Qt::Key_Enter);
此外,您可以使用QCOMPARE 宏测试文本。
QCOMPARE( sourceText, targetText );
附加
我认为QTimer::singleShot对解决您的问题很有用。
QMessageBox test;
QDialog& dlg = test;
QTimer::singleShot( 2000, &dlg, SLOT( close() ) );
dlg.exec();
在上面的代码中,测试消息框将在 2 秒后关闭。所以,你的代码也许..
MainWindow mwindow;
QDialog& dlg = mwindow;
QTimer::singleShot( 2000, &dlg, SLOT( close() ) ); //or SLOT( quit() )?
QTest::mouseClick(mwindow->showButton, QtCore::Qt::LeftButton)
但是,我没有测试过。另外,请尝试阅读这篇文章。我希望这可以帮助你。