Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-138076

Undeprecate QApplication::setActiveWindow

    XMLWordPrintable

Details

    • All

    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:

      1. It requires drawing the widget which adds performance overhead
      2. Showing the widget may not be possible in CI environments.
      3. 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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            srutledg Shawn Rutledge
            marcusle Marcus Leivo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes