Qt: How do I get the currently running window?

前提是你 提交于 2019-12-10 13:04:28

问题


I'm writing a test app which simulates key presses and I would like to get what window is displayed after each key presses. Here's the code block.

std::auto_ptr<MyForm> pForm(new MyForm(3,3)); 
QTest::keyPress(pForm.get(), Qt::Key_0); 

After pressing 0 here, A window is gonna show up and I would like to check what window it is so I could QCompare/evaluate it later.

Any Ideas?

Updated:

I'm getting a segmentation fault when I use

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"));

回答1:


If all your windows have been created through your application, you can use the QApplication class. By example, the activeWindow() function returns the widget that have the input focus. But there's a lot of other functions that can help you.

Hope that helps



来源:https://stackoverflow.com/questions/4212852/qt-how-do-i-get-the-currently-running-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!