Testing Alien Widgets of Qt Applications

Applies to TestComplete 15.68, last modified on October 16, 2024

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.

TestComplete provides access to non-windowed components of Qt applications the same way it provides access to windowed components. You can explore alien widget controls in the Object Browser, work with their properties and call their methods in your tests.

Alien widgets of a Qt application can become windowed during testing. This happens because 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 can occur during the test execution.

There are two 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 full names to address Qt controls in tests.

    If you still want to use alien widgets in your Qt applications, it is recommended that you use the full names of Qt controls to address them in your tests. For example, if you use variables to refer to Qt controls and the Unable to find the object error occurs during the script run, insert a script line that obtains the required Qt control again before the script line where the error occurs.

    Note: To access alien widget controls in tests, you can use the QtObject method and specify the needed object by using the QtIndex property. If creation of non-windowed controls is disabled, Qt objects will be specified by the window’s current front-to-back onscreen position (using the z-order index). These indexes cannot coincide with the QtIndex values used earlier, so, you may need to modify your tests to use the Index property to address objects.

See Also

Testing Qt Applications
Debug Info Agent™

Highlight search results