cast
Object cast(object, type)
Casts the object
to the given type
and returns a reference to that object, or to a new copy of the object if the object
is of an immutable type. (A suitable object can be obtained using the Object waitForObject(objectOrName) function or the Object findObject(objectName) function.) The desired type
can be specified either by name (as a string) or by using a type object.
For mutable objects the object
itself is modified.
If the cast fails the object reference is returned unchanged.
Note: Python programmers should be aware that integer type conversions such as int(x)
will not work; use x = cast(x, int)
or x = cast(x, "int")
instead. Or if you prefer, do import __builtin__
(Python 2) or import builtins
(Python 3), and then use x = __builtin__.int(x)
(Python 2) or x = builtins.int(x) (Python 3)
. This is necessary because Squish implements its own int
object in Python.
This function makes it possible to downcast (e.g., from QWidget
to QTextEdit
), but does not do runtime type checking. See Event Handlers for Specific Objects for an example of use. For a cast that uses RTTI, see castToQObject().
© 2024 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.