Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead

Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead

Scheduled Pinned Locked Moved Solved Qt 6
qml + js
6 Posts 4 Posters 2.4k 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.
  • A Offline
    A Offline
    aarelovich
    wrote on 21 Sept 2021, 19:34 last edited by aarelovich
    #1

    0

    I have the following issue.

    I'm using QML for my application frontend.

    For one of my componentes I use a ListView that uses a custom delegate that contains it's own index (and some other data) in a a variable called vmIndex. Here is the declaration of the list view:

    ListView {
                        id: studySelectListView
                        anchors.fill: parent
                        model: studySelectList
                        delegate: VMStudyEntry {
                            width: studySelectBackground.width
                            height: studySelectBackground.height/4
                            onItemSelected: {
                                selectionChanged(vmIndex,true); // LINE WITH WARNING
                            }
                        }
                    }
    

    Now, when the item is selected I need to call a function called selectionChange and send vmIndex as a parameter to that function.

    The VMStudyEntry is this:

    Item {
        id: vmStudyEntry
    
        signal itemSelected(int vmIndex);
    
        MouseArea {
            anchors.fill: parent
            onClicked: {
                vmStudyEntry.itemSelected(vmIndex);
            }
        }
        Rectangle {
            id: dateRect
            color: vmIsSelected? "#3096ef" : "#ffffff"
            border.color: vmIsSelected? "#144673" : "#3096ef"
            radius: mainWindow.width*0.005
            border.width: mainWindow.width*0.0005
            anchors.fill: parent
            Text {
                font.family: viewHome.gothamR.name
                font.pixelSize: 12*viewHome.vmScale
                text: vmStudyName
                color: vmIsSelected? "#ffffff" : "#000000"
                anchors.centerIn: parent
            }
        }
    
    }
    

    This all worked perfectly on Qt 5.13.2. But I now moved to Qt 6.1.2. The code actually still works, as far as I can see but I'm getting this warning when I click in one of the items in the list.

    Parameter "vmIndex" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.
    

    The line that has this warning is identifed above. Can anyone tell me how I can redefine this in order to make this warning go away?

    R 1 Reply Last reply 23 Sept 2021, 14:35
    1
    • A aarelovich
      21 Sept 2021, 19:34

      0

      I have the following issue.

      I'm using QML for my application frontend.

      For one of my componentes I use a ListView that uses a custom delegate that contains it's own index (and some other data) in a a variable called vmIndex. Here is the declaration of the list view:

      ListView {
                          id: studySelectListView
                          anchors.fill: parent
                          model: studySelectList
                          delegate: VMStudyEntry {
                              width: studySelectBackground.width
                              height: studySelectBackground.height/4
                              onItemSelected: {
                                  selectionChanged(vmIndex,true); // LINE WITH WARNING
                              }
                          }
                      }
      

      Now, when the item is selected I need to call a function called selectionChange and send vmIndex as a parameter to that function.

      The VMStudyEntry is this:

      Item {
          id: vmStudyEntry
      
          signal itemSelected(int vmIndex);
      
          MouseArea {
              anchors.fill: parent
              onClicked: {
                  vmStudyEntry.itemSelected(vmIndex);
              }
          }
          Rectangle {
              id: dateRect
              color: vmIsSelected? "#3096ef" : "#ffffff"
              border.color: vmIsSelected? "#144673" : "#3096ef"
              radius: mainWindow.width*0.005
              border.width: mainWindow.width*0.0005
              anchors.fill: parent
              Text {
                  font.family: viewHome.gothamR.name
                  font.pixelSize: 12*viewHome.vmScale
                  text: vmStudyName
                  color: vmIsSelected? "#ffffff" : "#000000"
                  anchors.centerIn: parent
              }
          }
      
      }
      

      This all worked perfectly on Qt 5.13.2. But I now moved to Qt 6.1.2. The code actually still works, as far as I can see but I'm getting this warning when I click in one of the items in the list.

      Parameter "vmIndex" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.
      

      The line that has this warning is identifed above. Can anyone tell me how I can redefine this in order to make this warning go away?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 23 Sept 2021, 14:35 last edited by
      #2

      @aarelovich said in Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead:

      MouseArea {
      anchors.fill: parent
      onClicked: {
      vmStudyEntry.itemSelected(vmIndex);
      }
      }

      where does vmIndex come from in the first place when you emit the signal?
      Looks to me that vmIndex is available in the global/parent context and then also used as a name in the signal parameter?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Dmitriano
        wrote on 23 Sept 2021, 15:16 last edited by Dmitriano
        #3

        I have the same warning messages in QT 6.2:

        qt.qml.context: qrc:/PeaksTab.qml:445:13 Parameter "order" is not declared. Injection of parameters into signal handlers is deprecated. Use JavaScript functions with formal parameters instead.
        

        where order is a parameter of a signal:

            class PriceChart : public QQuickPaintedItem
            {
            ...
                signals:
            
                void dropOrder(QObject* order);
            }    
        

        The signal is handled in QML:

                    onDropOrder:
                    {
                        market.dropOrder(order.id)
                    }
        

        There are no warning messages in QT5.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mingr
          wrote on 23 Sept 2021, 15:54 last edited by
          #4

          This can actually be solved by using functions like:

          onDropOrder: function(order) {
               market.dropOrder(order.id)
          }
          
          A 1 Reply Last reply 24 Sept 2021, 09:18
          4
          • M Offline
            M Offline
            mingr
            wrote on 23 Sept 2021, 15:54 last edited by
            #5

            Basically, you have to capture the input arg now

            1 Reply Last reply
            1
            • M mingr
              23 Sept 2021, 15:54

              This can actually be solved by using functions like:

              onDropOrder: function(order) {
                   market.dropOrder(order.id)
              }
              
              A Offline
              A Offline
              aarelovich
              wrote on 24 Sept 2021, 09:18 last edited by
              #6

              @mingr This is the right answer to my question. As this fixed my issue. Thank you!!

              1 Reply Last reply
              0

              6/6

              24 Sept 2021, 09:18

              • Login

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