Accessing Native Properties and Methods of Qt Objects

Applies to TestComplete 14.71, last modified on April 22, 2021

TestComplete provides you with access to individual objects of Qt applications, their internal properties and methods. The following sections describe how you can access these native properties and methods from your tests:

About Accessing Native Properties and Methods

TestComplete identifies individual GUI objects in Qt applications and provides specialized methods and properties for automating various operations on these objects, getting object data, checking state and so on. However, if these predefined properties and methods are insufficient for your testing needs, you can use native properties and methods of Qt objects to complete desired tasks. These are the same properties and methods that are available for use in the tested application’s source code as well as custom properties and methods implemented by the application developers. This way, you can perform almost any operations in the tested Qt application, even those that are not accessible via the application’s GUI.

The Object Browser marks objects of Qt applications with the glyph. To view native properties and methods available for a Qt object, use the Object Spy or Object Browser in the Advanced view mode. Native properties and methods of Qt objects are displayed under the Qt category (see Important Notes for details).

Native Properties of a Qt TextEdit Object in Object Browser

Click the image to enlarge it.

TestComplete lets you access only those properties of Qt objects that are listed in meta-information of an object and have standard QVariant-compatible data types. For more information, see Using Native Qt Methods and Properties in Testing.

For more information on how to refer to objects in Qt applications, see Addressing Objects in Qt Applications.

Getting Access to Qt Applications Native Properties and Methods

By default, TestComplete enables you to access all public methods from your tests and some of public properties (for more information, see Using Native Qt Methods and Properties in Testing). You do not need to prepare your application in any special way to call these methods and properties from your tests.

If you need to get access to an application’s protected and private members, do the following:

  1. Compile your application with debug information. For a detailed description of compiler settings, see the Compiler Settings for Visual C++ 8.0 and Later Open Applications (Unmanaged Code) topic.

  2. Enable the Enable Debug Agent and Read debug information for statically linked libraries options in the Project Properties - Debug Agent Options dialog.

    Tip: Debug Info Agent™ is enabled by default.

After you do this, you will be able to access protected and private properties and methods and address them from your tests.

Getting and Setting Native Object Properties

To access an object’s property in script code, you specify the property name after the object name using the dot operator "." (in VBScript, JScript, Python and DelphiScript projects) or the square bracket notation [" "] (in C++Script and C#Script projects).

For example, you can get and set a Qt form’s title using its native windowTitle property in the following way:

JavaScript, JScript

var title = Aliases.textedit.TextEdit.windowTitle;
Aliases.textedit.TextEdit.windowTitle = "New Window Title";

Python

title = Aliases.textedit.TextEdit.windowTitle;
Aliases.textedit.TextEdit.windowTitle = "New Window Title";

VBScript

Dim title
title = Aliases.textedit.TextEdit.windowTitle
Aliases.textedit.TextEdit.windowTitle = "New Window Title"

DelphiScript

procedure Test;
var title;
begin
  …
  title := Aliases.textedit.TextEdit.windowTitle;
  Aliases.textedit.TextEdit.windowTitle := 'New Window Title';
  …
end;

C++Script, C#Script

var title = Aliases["textedit"]["TextEdit"]["windowTitle"];
Aliases["textedit"]["TextEdit"]["windowTitle"] = "New Window Title";

In keyword tests, you can retrieve an object’s property value and save it to a test variable using the Set Variable Value operation. To change a property value, you can use the On-Screen Action operation to call the property’s [Set] method. For more information, see Getting and Setting Object Property Values.

Saving a Qt object’s native property value to a test variable

Click the image to enlarge it.

Setting a new value for a Qt object’s native property

Click the image to enlarge it.

You can also create checkpoints for verifying values of native object properties.

Calling Native Object Methods

To call an object’s method from script code, you use the dot operator "." (in VBScript, JScript, Python and DelphiScript projects) or the square bracket notation [" "] (in C++Script and C#Script projects) to specify the method name after the object name.

For example, in script code you can call the native SetFocus method of a Qt combo box as follows:

JavaScript, JScript

Aliases.textedit.TextEdit.ComboBox.setFocus();

Python

Aliases.textedit.TextEdit.ComboBox.setFocus();

VBScript

Aliases.textedit.TextEdit.ComboBox.setFocus

DelphiScript

Aliases.textedit.TextEdit.ComboBox.setFocus();

C++Script, C#Script

Aliases["textedit"]["TextEdit"]["ComboBox"]["setFocus"]();

In keyword tests, you can use the On-Screen Action operation to call an object’s native method. For more information, see Calling Object Methods.

Invoking a Qt object’s native method

Click the image to enlarge it.

Important Notes

  • In the Object Spy or Object Browser, native properties and methods of Qt objects are only displayed in the Advanced view mode. By default, TestComplete provides you with access to Qt public properties and methods.

    In addition, if the Debug Info Agent™ is enabled and the Read debug information for statically linked libraries option is enabled, TestComplete provides you with access to protected and private properties and methods.

  • If a native property or method has the same name as a test object property (method) provided by TestComplete, the native property (method) can be accessed via the NativeQtObject property. For example, you can access the native Name property of a Qt application’s form as follows:

    JavaScript, JScript

    Aliases.textedit.TextEdit.NativeQtObject.Name

    Python

    Aliases.textedit.TextEdit.NativeQtObject.Name

    VBScript

    Aliases.textedit.TextEdit.NativeQtObject.Name

    DelphiScript

    Aliases.textedit.TextEdit.NativeQtObject.Name

    C++Script, C#Script

    Aliases["textedit"]["TextEdit"]["NativeQtObject"]["Name"]

  • The leading underscore ( _ ) in property and method names is replaced with the character z. For example, a property named _flag is accessible as zflag, a method named __reset() is accessible as z_reset(), and so on.

  • If the object contains overloaded methods (methods with the same name but different parameters and return value types), TestComplete appends indexes to method names in order to distinguish between them. For example, GetChildAtPoint() and GetChildAtPoint_2(). To determine which index-suffixed method name corresponds to which overloaded method, examine the method’s parameter list in the Object Spy, Object Browser or Code Completion.

  • Some native properties and methods of Qt objects are unavailable to TestComplete. For more information, see Object Properties, Fields and Methods That Are Unavailable to TestComplete.

See Also

Testing Qt Applications
Testing Qt Applications - Overview

Highlight search results