QT unit-testing : qtestlib Segmentation fault
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...
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!
精彩评论