Property Problems (Qt)

Last edited on

Suppose you have an AUT that has a QStackedWidget and you want to verify how many widgets are in the stack.

def main():
    # ... 
    # This is the QStackedWidget we are interested in
    contactsPane = waitForObject(names.ContactsStackedFrame)
    count = contactsPane.count() # Error
    test.verify(count == 5)

Unfortunately, this doesn’t work: Python will throw an error “‘int’ object is not callable” at the line marked Error.

This problem arises because QStackedWidgets have both a count() function and a count property, and when Squish is faced with a function and a property with the same name it always chooses the property.

The solution is simple — we just use the count property, replacing the Error line with:

count = contactsPane.count # OK