简体   繁体   中英

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 .

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

So what is the "right way" to do this using QTest primitives?

What if you specify Qt::WA_DeleteOnClose attribute for the widget and wait on its destroyed() signal?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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