PDA

View Full Version : QTest - Unable to pass Qt::Enter to QPushButton



bedbuffer
31st January 2011, 10:22
I'm creating an automated test application using QTest Library. I'm able to simulate key presses on the application except when it gets to a window having QDialogButtonBox (Save, and Cancel). Here's my sample code:

std::auto_ptr<MainForm> myForm( new MainForm( 3, 3 ));
myForm->show();
QTest::keyPress(myForm.get(), Qt::Key_0, NULL, 1000);
QTest::keyRelease(myForm.get(), Qt::Key_0, NULL, 100);
QWidget *pWin = QApplication::activeWindow();
QCOMPARE(QString(pWin->objectName()), QString("MyMainForm"));

now when it gets to the next window, it has several controls where the input focus is on a text edit control. When I press Enter, it presses the "Save" button. So theoretically, if I should pass Qt::Enter to the Form, it should press the "Save" button as well. However when I try to pass a keyPress:

QTest::keyPress(pWin, Qt::Key_Enter, 1000);

nothing happens... what do you think is going on? I've tried setFocus() to the button but nothing happens as well...

wysota
31st January 2011, 10:31
You probably want Qt::Key_Return and not Qt::Key_Enter.

bedbuffer
1st February 2011, 03:57
You probably want Qt::Key_Return and not Qt::Key_Enter.

I have already tried that... doesn't make a difference though... :(