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. Connections in Repeater and "deprecated implicitly defined onFoo properties" VS "functions are not supported in UI"
QtWS25 Last Chance

Connections in Repeater and "deprecated implicitly defined onFoo properties" VS "functions are not supported in UI"

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
repeaterconnectionsqml
7 Posts 2 Posters 1.3k Views
  • 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.
  • H Offline
    H Offline
    Hitokage
    wrote on last edited by
    #1

    Hello,
    I have a repeater dynamically populated with images where after clicking on the image, I need to call a function with the element index as an argument.
    This is the code:

    Repeater {
    model: 0
    Image {
     source: "qrc:/images/image.svg"
     MouseArea {
      anchors.fill: parent
       Connections {
       onClicked: {
        myFunction(index)
                                }}}}}
    

    Now I got the warning

    QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
    

    so I changed it to:

    ...
       Connections {
       function onClicked() {
        myFunction(index)
       }
    

    But now it gives me this:

    Functions are not supported in a Qt Quick UI form (M222)
    

    What is the right solution when converting such kind of code into the new syntax?
    Thanks and have a nice day!

    ODБOïO 1 Reply Last reply
    0
    • H Hitokage

      Hello,
      I have a repeater dynamically populated with images where after clicking on the image, I need to call a function with the element index as an argument.
      This is the code:

      Repeater {
      model: 0
      Image {
       source: "qrc:/images/image.svg"
       MouseArea {
        anchors.fill: parent
         Connections {
         onClicked: {
          myFunction(index)
                                  }}}}}
      

      Now I got the warning

      QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
      

      so I changed it to:

      ...
         Connections {
         function onClicked() {
          myFunction(index)
         }
      

      But now it gives me this:

      Functions are not supported in a Qt Quick UI form (M222)
      

      What is the right solution when converting such kind of code into the new syntax?
      Thanks and have a nice day!

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by ODБOï
      #2

      hi

      @Hitokage said in Connections in Repeater and "deprecated implicitly defined onFoo properties" VS "functions are not supported in UI":

      Functions are not supported in a Qt Quick UI form (M222)

      You can't declare/call functions in the ui file( <fileName>.ui.qml ).
      Put your code in a new qml Component (.qml file) and it will work
      https://doc.qt.io/qtcreator/creator-quick-ui-forms.html
      note you can embed qml components (with functions) in your ui forms

      If you want to use ui files, then your need to separate the logic and the view

      // ViewForm.ui.qml. No logic in here, juste the view  
      import QtQuick 2.4
      Rectangle{  
      //...
      border.width:1
      Repeater {anchors.fill:parent} 
      }
      
      // ViewForm.qml. Logic goes here 
      import QtQuick 2.4
      ViewForm {
        delegate: Image{
            MouseArea{}
          }
      }
      
      // use ViewForm somewhere in your app
      ViewForm{}
      
      1 Reply Last reply
      1
      • H Offline
        H Offline
        Hitokage
        wrote on last edited by Hitokage
        #3

        @LeLev Thank you!
        Ah, so you mean like using the ViewForm item in the Repeater instead of the Image?

        ODБOïO 1 Reply Last reply
        0
        • H Hitokage

          @LeLev Thank you!
          Ah, so you mean like using the ViewForm item in the Repeater instead of the Image?

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          @Hitokage said in Connections in Repeater and "deprecated implicitly defined onFoo properties" VS "functions are not supported in UI":

          so you mean like using the ViewForm item in the Repeater instead of the Image?

          No that wouldn't make sense at all, i just accidentally used ListView instead of Repeater, i will correct it now

          1 Reply Last reply
          1
          • H Offline
            H Offline
            Hitokage
            wrote on last edited by
            #5

            @LeLev Sorry, my bad. I got confused! The only thing I still don't understand is the delegate part. Does it, in other words, serve as the Repeater item? How does the delegate connect to the Repeater? What if there are multiple Repeaters?

            ODБOïO 1 Reply Last reply
            0
            • H Hitokage

              @LeLev Sorry, my bad. I got confused! The only thing I still don't understand is the delegate part. Does it, in other words, serve as the Repeater item? How does the delegate connect to the Repeater? What if there are multiple Repeaters?

              ODБOïO Offline
              ODБOïO Offline
              ODБOï
              wrote on last edited by
              #6

              @Hitokage https://doc.qt.io/qt-5/qml-qtquick-repeater.html#delegate-prop

              1 Reply Last reply
              1
              • H Offline
                H Offline
                Hitokage
                wrote on last edited by
                #7

                @LeLev Many thanks!

                1 Reply Last reply
                1

                • Login

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