QT:单元测试分段错误
下面是用于模拟菜单上按键的代码块。我可以深入浏览应用程序的菜单,但是当我返回主窗体时,我遇到了分段错误....:(
首先我显示我的应用程序:
std::auto_ptr<MyForm> mainForm( new MyForm( 3, 3 ));
mainForm->show();
然后模拟按键以显示主菜单:
QTest::keyPress(mainForm.get(), Qt::Key_0, NULL, 300);
QTest::keyRelease(mainForm.get(), Qt::Key_0, NULL, 300);
QWidget *pWin = QApplication::activeWindow();
QCOMPARE(QString(pWin->objectName()), QString("MainMenu"));
然后模拟另一个按键返回到我的主应用程序:
QTest::keyPress(pWin, Qt::Key_Escape, NULL, 300);
QTest::keyRelease(pWin, Qt::Key_Escape, NULL, 300);
pWin = QApplication::activeWindow();
QCOMPARE(QString(pWin->objectName()), QString("MainForm"));
这就是我遇到分段错误的地方...有人能告诉我是什么导致了这个错误吗?
Below is a code block for simulating key presses on a menu. I can navigate deep into the menus of my application but when I get back to the main form, I'm getting a segmetation error.... :(
first I show my Application:
std::auto_ptr<MyForm> mainForm( new MyForm( 3, 3 ));
mainForm->show();
Then simulate a keyPress to show the main menu:
QTest::keyPress(mainForm.get(), Qt::Key_0, NULL, 300);
QTest::keyRelease(mainForm.get(), Qt::Key_0, NULL, 300);
QWidget *pWin = QApplication::activeWindow();
QCOMPARE(QString(pWin->objectName()), QString("MainMenu"));
Then simulate another keyPress to go back to my main application:
QTest::keyPress(pWin, Qt::Key_Escape, NULL, 300);
QTest::keyRelease(pWin, Qt::Key_Escape, NULL, 300);
pWin = QApplication::activeWindow();
QCOMPARE(QString(pWin->objectName()), QString("MainForm"));
This is where I'm getting the segmentation fault... Can anybody tell me what's causing this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先检查
QApplication::activeWindow()
的结果。从文档..Start with checking the result of
QApplication::activeWindow()
. From the docs..