Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
None
-
None
Description
QTest contains a nice suite for testing widgets. With QTest, one can test changes in UI. To simulate e.g. mouse events and key presses, the widget needs to be active. There are at least two ways to set the widget active.
The first way is to call show and activate:
widget->show();
widget->activateWindow();
QTest::qWaitForWindowActive(widget);
/* QTest::keyClick etc. here... */
The second way is a single line of code:
QApplication::setActiveWindow(widget);
/* QTest::keyClick etc. here... */
The first way will be the preferred way in the future, but it has major drawbacks:
- It requires drawing the widget which adds performance overhead
- Showing the widget may not be possible in CI environments.
- It's more complex and more bug prone. For example, if you forget to call QTest::qWaitForWindowActive your tests may now break depending on your window manager. Perhaps only on your CI machine and not on your development machine.
QApplication::setActiveWindow just works™ and production code depends on it. Without a proper replacement, deprecating it will stop at least some people from upgrading in the future. So please, consider undeprecating QApplication::setActiveWindow or implementing a proper replacement.