Frage

I am scripting automatic tests of Qt application using Squish framework. Spy in Squish IDE can view properties and methods of Qt widget selected by "spy picker". In Spy perspective enable Window -> Show View -> Methods.

I can see in Methods view something like void setParent(QObject*) - method name, return and parameter types.

In runtime from Python test script I can get widget properties, for example isActiveWindow -> true, by calling

aWidget = waitForObject("...")
aMap = object.properties( aWidget )

Widget methods are available from Python, for example I can call:

>>> aWidget.isModal()
0

But how to get list of widget methods signatures, as in Methods view in IDE? All I came up with is

>>> dir(this)
['BackButtonPressed', 'ButtonPressed', ...

But of course it lists only method names not signatures, there are no declared parameter types or return types. Spy somehow gets the signatures, how can I get them in runtime from Python?

War es hilfreich?

Lösung

In order to obtain the widget's method signature you can use its meta object information. For example, below is the Python script (Squish test script) that prints out widget's all public slots (method) signatures:

widget = waitForObject(':Test Widget')

metaObject = widget.metaObject();
methodCount =  metaObject.methodCount()

for x in range(0, methodCount):
    method = metaObject.method(x)
    test.log(method.signature())
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top