Qt:如何获取当前正在运行的窗口?
我正在编写一个模拟按键的测试应用程序,我想了解每次按键后显示的窗口。这是代码块。
std::auto_ptr<MyForm> pForm(new MyForm(3,3));
QTest::keyPress(pForm.get(), Qt::Key_0);
在此处按 0 后,将显示一个窗口,我想检查它是什么窗口,以便稍后进行 QCompare/评估。
有什么想法吗?
更新:
我在使用时遇到分段错误
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"));
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"));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果所有窗口都是通过应用程序创建的,则可以使用
QApplication
类。例如,
activeWindow()
函数返回具有输入焦点的小部件。但还有很多其他功能可以帮助您。希望有帮助
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