Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. TS-like syntax for QML types
Forum Updated to NodeBB v4.3 + New Features

TS-like syntax for QML types

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 533 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KoneTaH
    wrote on 28 Feb 2021, 15:30 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kenneth.fernandez
      wrote on 5 Mar 2021, 19:21 last edited by kenneth.fernandez 3 May 2021, 19:22
      #2

      @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,

      --
      Lic-Ing. Kenneth Fernández Esquivel
      Embedded Software Engineer
      RidgeRun Engineering Ltd.
      www.ridgerun.com
      Email: kenneth.fernandez@ridgerun.com
       San Juan, La Unión. Cartago. Costa Rica

      K 1 Reply Last reply 5 Mar 2021, 23:38
      2
      • K kenneth.fernandez
        5 Mar 2021, 19:21

        @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,

        K Offline
        K Offline
        KoneTaH
        wrote on 5 Mar 2021, 23:38 last edited by
        #3

        @kenneth-fernandez Thanks!

        1 Reply Last reply
        1

        1/3

        28 Feb 2021, 15:30

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved