waitForObjectItem (Qt)

Object waitForObjectItem(objectOrName, itemOrIndex)

Object waitForObjectItem(objectOrName, itemOrIndex, timeoutMSec)

Waits until the objectOrName object is accessible (i.e., it exists and is visible and enabled), and contains an item that is identified by the itemOrIndex and that is itself accessible.

The given name can also be a native script dictionary (resp. hash) value.

This function is typically used to access items inside containers such as lists, tables, and trees.

The itemOrIndex must be formatted according to what kind of view it is.

  • For QListView, where strings may appear multiple times, a specific item can be selected by appending (_) followed by the item's occurrence index, to the non-unique string. For example, "itemtext_3" would retrieve the third item in the list which contains the "itemtext" string.
  • For QTreeView, it must be a period (.)-separated hierarchy path string such as Mammals.Felines.Cats.
  • For QTableView, it can be a row/column string like "4/21". It can also be a string to search for in the table cells.

Note: If you need to search for a string that contains / in a QTableView, (or _ in a QListView) escaping the delimiter may not work. Instead, use a helper function which creates a Real Name for use with waitForObject. For example:

def waitForObjectItemQTableView(table, itemText):
    realName = {"type": "QModelIndex", "container": table, "text": itemText}
    return waitForObject(realName)
function waitForObjectItemQTableView(table, itemText) {
    var realName = {"type": "QModelIndex", "container": table, "text": itemText};
    return waitForObject(realName);
}
sub waitForObjectItemQTableView
{
    my ($table, $itemText) = @_;
    my $realName = {"type" => "QModelIndex", "container" => $table, "text" => $itemText};
    return waitForObject($realName);
}
def waitForObjectItemQTableView(table, itemText)
    realName = {:type => "QModelIndex", :container => table, :text => itemText}
    return waitForObject(realName)
proc waitForObjectItemQTableView {table itemText} {
    set realName [::Squish::ObjectName container $table text $itemText type QModelIndex]
    return [waitForObject $realName]
}

The return value is a reference to the item. (The reference can be used with other Squish functions.)

The function raises a (catchable) LookupError exception on failure, i.e., if it times out.

The function waits for the time defined by the testSettings.waitForObjectTimeout property or if the optional timeoutMSec parameter is used, that many milliseconds.

Additional processing can be done on the object items before this function returns, by providing a user-defined callback function. See waitUntilObjectItemReady(item) for details.

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners.
The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.

Search Results