简体   繁体   English

问:我如何获得当前运行的窗口?

[英]Qt: How do I get the currently running window?

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. 在这里按0后,会出现一个窗口,我想查看它是什么窗口,以便我可以稍后进行QCompare /评估。

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

If all your windows have been created through your application, you can use the QApplication class. 如果您的所有窗口都是通过应用程序创建的,则可以使用QApplication类。 By example, the activeWindow() function returns the widget that have the input focus. 例如, activeWindow()函数返回具有输入焦点的窗口小部件。 But there's a lot of other functions that can help you. 但是还有很多其他功能可以帮到你。

Hope that helps 希望有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM