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"

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 18 Mar 2021, 17:06 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!

    O 1 Reply Last reply 18 Mar 2021, 18:15
    0
    • H Hitokage
      18 Mar 2021, 17:06

      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!

      O Offline
      O Offline
      ODБOï
      wrote on 18 Mar 2021, 18:15 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 18 Mar 2021, 18:22 last edited by Hitokage
        #3

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

        O 1 Reply Last reply 18 Mar 2021, 18:38
        0
        • H Hitokage
          18 Mar 2021, 18:22

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

          O Offline
          O Offline
          ODБOï
          wrote on 18 Mar 2021, 18:38 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 18 Mar 2021, 18:47 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?

            O 1 Reply Last reply 18 Mar 2021, 19:46
            0
            • H Hitokage
              18 Mar 2021, 18:47

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

              O Offline
              O Offline
              ODБOï
              wrote on 18 Mar 2021, 19:46 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 19 Mar 2021, 07:01 last edited by
                #7

                @LeLev Many thanks!

                1 Reply Last reply
                1

                1/7

                18 Mar 2021, 17:06

                • Login

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