开发者

QT: unit-testing segmentation fault

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("M开发者_如何学GoainForm"));

This is where I'm getting the segmentation fault... Can anybody tell me what's causing this error?


Start with checking the result of QApplication::activeWindow(). From the docs..

Returns the application top-level window that has the keyboard input focus, or 0 if no application window has the focus. There might be an activeWindow() even if there is no focusWidget(), for example if no widget in that window accepts key events.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜