TS-like syntax for QML types
-
Hi all! I recently noticed that some parts of the documentation mentioned a new typing syntax (TypeScript-like). For example, here is an old syntax:
// MyItem.qml import QtQuick 2.0 Item { function myQmlFunction(msg) { console.log("Got message:", msg) return "some return value" } }
// MyItem.qml import QtQuick 2.0 Item { id: item width: 100; height: 100 signal qmlSignal(var anObject) MouseArea { anchors.fill: parent onClicked: item.qmlSignal(item) } }
and here is a new one:
// MyItem.qml import QtQuick 2.0 Item { function myQmlFunction(msg: string) : string { console.log("Got message:", msg) return "some return value" } }
// MyItem.qml import QtQuick 2.0 Item { id: item width: 100; height: 100 signal qmlSignal(anObject: Item) MouseArea { anchors.fill: parent onClicked: item.qmlSignal(item) } }
Does anyone know when exactly support for the new syntax was added and where is it mentioned? Starting from what version of Qt can it be safely used? I tried to find some traces in changelists, but no luck. Thanks in advance for your help.
-
@KoneTaH said in TS-like syntax for QML types:
function myQmlFunction(msg: string)
Hi @KoneTaH ,
That feature is supported from version Qt 5.15 / Qt Quick 2.0 ahead. As Qt is doing some changes for QML this will be more common in the future releases.
Here is an example:
https://doc.qt.io/qt-5/qtqml-cppintegration-interactqmlfromcpp.html
I hope this give some overview,
-
@kenneth-fernandez Thanks!