QT 单元测试:qtestlib 分段错误
我正在编写一个测试应用程序,用于测试显示的表单是否是正确的表单。这是在按下菜单上的某个键后发生的。这是一个代码块,我遇到了分段错误。
std::auto_ptr<MyForm> pForm(new MyForm(3,3));
QTest::keyPress(pForm.get(), Qt::Key_0);
QWidget *pWin = QApplication::activeWindow();
QCOMPARE(pWin->windowTitle(), QString("My Second Menu"));
问题:
- 当您只是模拟按键时,真的有可能获取当前活动的窗口吗?
- 我在使用 activeWindow 时得到一个空指针,无论如何,您是否可以获得按键时应该在屏幕上显示的窗口的句柄?
谢谢...
I'm writing a test app that would test if the displayed form is the correct form. This is after pressing a key on a menu. Here's a code block where I'm getting a segmentation fault.
std::auto_ptr<MyForm> pForm(new MyForm(3,3));
QTest::keyPress(pForm.get(), Qt::Key_0);
QWidget *pWin = QApplication::activeWindow();
QCOMPARE(pWin->windowTitle(), QString("My Second Menu"));
Questions:
- Is it really possible to get the currently active window when you are just simulating key presses?
- I'm getting a null pointer when using activeWindow, is there anyway you could get the handle of the window that's supposed to show on the screen upon a keypress?
Thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
弗兰克是对的。该窗口尚未同步激活。添加作为 keyPress 参数的延迟确实解决了问题。谢谢弗兰克!
Frank was right. The window has not been acitivated synchronously. Adding a delay which is a parameter of keyPress did resolve the problem. Thanks Frank!