You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can also use the XMLRPC client to list the available methods. The complete list of methods are also available in the [source](lib/src/AnyRpcServer.cpp).
@@ -168,6 +169,67 @@ More specifically, Spix's matching processes works as follows:
168
169
*`<root>` matches a top-level [`QQuickWindow`](https://doc-snapshots.qt.io/qt6-dev/qquickwindow.html) whose `objectName` (or `id` if `objectName` is empty) matches the specified string. Top-level windows are enumerated by [`QGuiApplication::topLevelWindows`](https://doc.qt.io/qt-6/qguiapplication.html#topLevelWindows).
169
170
*`<child>` matches the first child object whose `objectName` (or `id` if `objectName` is empty) matches the specified string using a recursive search of all children and subchildren of the root. This process repeats for every subsequent child path entry.
170
171
172
+
### Invoking QML methods
173
+
174
+
Spix can directly invoke both internal and custom methods in QML objects: this can be a handy way to automate interactions that Spix doesn't support normally. For example, we can control the cursor in a `TextArea` by calling [`TextArea.select`](https://doc-snapshots.qt.io/qt6-6.2/qml-qtquick-textedit.html#select-method):
| int |\<int\>| int | number | Values over/under int max are upcasted to double |
206
+
| bool |\<boolean\>| bool | boolean ||
207
+
| str |\<string\>| string | string ||
208
+
| float |\<double\>| double, real | number | Defaults to double |
209
+
| datetime.datetime |\<dateTime.iso8601\>| date | Date | No timezone support (always uses local timezone) |
210
+
| dict |\<struct\>| var | object | String keys only |
211
+
| list |\<array\>| var | Array ||
212
+
| None | no type | null, undefined | object, undefined | Defaults to null ||
213
+
214
+
In general Spix will attempt to coerce the arguments and return value to the correct types to match the method being invoked. Valid conversion are listed under the [`QVariant` docs](https://doc.qt.io/qt-5/qvariant.html#canConvert). If Spix cannot find a valid conversion it will generate an error.
215
+
```qml
216
+
Item {
217
+
id: item
218
+
function test(arg1: bool) {
219
+
...
220
+
}
221
+
}
222
+
```
223
+
```python
224
+
# ok
225
+
s.invokeMethod("root/item", "test", [False])
226
+
227
+
# argument will implicitly be converted to a boolean (True) to match the declaration type
228
+
s.invokeMethod("root/item", "test", [34])
229
+
230
+
# no conversion from object to boolean, so an error is thrown
231
+
s.invokeMethod("root/item", "test", [{}])
232
+
```
171
233
172
234
## Two modes of operation
173
235
In general, Spix can be used in two ways, which are different in how events are generated and sent
@@ -176,7 +238,7 @@ to your application:
176
238
### Generate Qt events directly
177
239
You can use Spix to directly create Qt events, either from C++ as a unit test, or from
178
240
an external script via the network through RPC. Since the Qt events are generated directly inside the
179
-
app, and do not come from the system, the mouse coursor will not actually move and interaction
241
+
app, and do not come from the system, the mouse cursor will not actually move and interaction
180
242
with other applications is limited. On the plus side, this mechanism is independent from
181
243
the system your app is running on and can easily be used to control software on an embedded
0 commit comments