0

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...

Owen
  • 4,063
  • 17
  • 58
  • 78
  • 1
    Two thoughts: 1. check that the code you'd expect to act on Key_0 is actually triggered and the menu is created. If not, try to show() the form. 2. The window might not be activated synchronously, but delayed, then your code wouldn't work. – Frank Osterfeld Nov 19 '10 at 08:37
  • Thanks dude... you were right... I added a delay in keyPress and it worked! :D – Owen Nov 19 '10 at 10:05

1 Answers1

0

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!

Owen
  • 4,063
  • 17
  • 58
  • 78