简体   繁体   English

如何使用QTestLib等待QWidget关闭? [Qt5]

[英]How can I wait for a QWidget to close using QTestLib? [Qt5]

I am writing a QTest based test case for a class that derives from QWidget . 我正在为从QWidget派生的类编写基于QTest的测试用例。

After showing the widget, I want the test to end as soon as the widget is closed . 显示小部件后,我希望测试在小部件关闭后立即结束

My first attempt was to use QSignalSpy , only to find out that QWidget really does not send out a signal on close() . 我的第一次尝试是使用QSignalSpy ,只是发现QWidget确实没有在close()上发出信号。

So what is the "right way" to do this using QTest primitives? 那么,使用QTest原语执行此操作的“正确方法”是什么?

What if you specify Qt::WA_DeleteOnClose attribute for the widget and wait on its destroyed() signal? 如果为窗口小部件指定 Qt :: WA_DeleteOnClose属性并等待其destroy ()信号怎么办?

pMyTestWidget->setAttribute(Qt::WA_DeleteOnClose);
pMyTestWidget->show();

// test thread...
QSignalSpy watchDog(pMyTestWidget, SIGNAL(destroyed(QObject*)));
watchDog.wait();

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

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