Preparing Alien Widgets in Qt Applications for Testing

Applies to TestLeft 15.40, last modified on March 17, 2022

Starting from version 4.4.0, Qt introduces alien widgets. Alien widgets are non-windowed components that do not have window handles associated with them.

You can access non-windowed components of Qt applications in the same way you access windowed components. You can explore alien widget controls in the TestLeft UI Spy, work with their properties and call their methods from tests.

Possible Issue

Alien widgets of a Qt application can become windowed during testing. This happens because Microsoft Active Accessibility sends the WM_GETOBJECT message to the top-level window of the tested Qt application’s process. In this case, the objects that correspond to alien widgets become non-existent and the object hierarchy of the tested Qt application changes. As a result, errors may occur in tests.

There are several ways to avoid this issue.

  • Disable creation of non-windowed Qt controls before testing

    You can do this in one of the following ways:

    • Compile the QtGui and QtGuid modules without the #define QT_NO_ACCESSIBILITY line. This will disable accessibility support and all the controls will be windowed.

    • Set the QT_USE_NATIVE_WINDOWS environment variable to 1 to disable the use of alien widgets in Qt applications.

    • Set the Qt::AA_NativeWindows attribute on your application. This attribute ensures that the widgets of your Qt application have native windows.

    • Set the Qt::WA_NativeWindow attribute on widgets in your Qt application. This attribute ensures that native windows are created for widgets and their ancestors.

    • Call the QWidget::winId method for widgets in your Qt application. This method forces native window creation for widgets and returns the window handle.

  • Use multiple criteria to identify Qt controls in tests

    To access alien widget controls in tests, use the QtPattern object and identify the needed object by using its QtIndex property.

    If you disable creation of non-windowed controls, TestLeft will use the window’s current front-to-back onscreen position (its z-order index) to identify Qt objects in applications. These indices may differ from QtIndex values. We recommend that you use the Index property to identify objects.

See Also

Preparing Qt Applications for Testing

Highlight search results