[Interest] QML type hints and their problems
ivan tkachenko
me at ratijas.tk
Wed Nov 3 02:35:04 CET 2021
Types, huh... Speaking of which, please, take a look at this piece of
documentation:
https://doc.qt.io/qt-6/qml-qtquick-item.html#containmentMask-prop
> It is also possible to define the contains() method on any QtObject in QML.
> For example, to create a circular item that only responds to events within
> its actual bounds:
>
> \table
> \row
> \li \image containmentMask-circle.gif
> \li \snippet qml/item/containmentMask-circle-js.qml 0
> \endtable
> containmentMask: QtObject {
> property alias radius: circle.radius
> function contains(point: point) : bool {
> return (Math.pow(point.x - radius, 2) + Math.pow(point.y -
radius, 2)) < Math.pow(radius, 2)
> }
> }
Don't you think it's a slightest bit weird that this example stops working if
you remove "type hints" from the contains() method? (Or whatever that editors/
syntax-highlight breaking but-otherwise-nice custom JS extension is called in
QML land.) I don't recall such fastidiousness being a documented feature,
ever.
> file:///home/ratijas/projects/q/qt6/qtdeclarative/src/quick/doc/snippets/qml/
item/containmentMask-circle-js.qml:55:1: QML Rectangle: QQuickItem: Object set
as mask does not have an invokable contains method, ignoring it.
It might seem like it was designed to support method overloading.
Unfortunately, that's not the case either:
> function contains(size: size): string {
> return "";
> }
> QQmlApplicationEngine failed to load component
> file:///home/ratijas/projects/q/qt6/qtdeclarative/src/quick/doc/snippets/qml/
item/containmentMask-circle-js.qml:70:18: Duplicate method name
> qml: Did not load any objects, exiting.
So, why is it a thing at all? There are no benefits, only broken syntax &
introspection.
--
ivan (@ratijas)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20211103/1da16a99/attachment.sig>
More information about the Interest
mailing list