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. How to use listview onAdd signal ?
Forum Updated to NodeBB v4.3 + New Features

How to use listview onAdd signal ?

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 5.6k 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.
  • W Offline
    W Offline
    wshn14
    wrote on last edited by
    #1

    I assign a model to a listview ,then the listview will add some items according to the delegate .But I can't connect the listview onAdd signal .
    The code below :
    @import Qt 4.7

    ListView
    {
    id: listView
    width:200
    height:800

    ListModel
    {
    id:listmodel
    ListElement
    {
    text:'text1'
    }
    ListElement
    {
    text:'text2'
    }
    }

    delegate:Rectangle
    {
    width:parent.width
    height:64

    Text
    {
    text:model.text
    }
    }

    onAdd:
    {
    console.log('on add sig')
    }
    model:listmodel
    }@

    use qmlviewer to run it ,but it comes a error . I want two 'on add sig ' output ,but nothing .So how to do ?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      You need to move the signal onAdd into the delegate. Also as per "this":https://bugreports.qt-project.org/browse/QTBUG-29384 bug report i modified your code as follows and the signal gets fired
      @
      import QtQuick 2.0

      ListView
      {
      id: listView
      width:200
      height:800

      ListModel
      {
          id:listmodel
          ListElement{
              text:'text1'
          }
          ListElement{
              text:'text2'
          }
      }
      
      delegate: Rectangle {
          Text { text:model.text }
      
          ListView.onAdd: {
              console.log("ad")
          }
      }
      
      model:listmodel
      
      MouseArea {
          anchors.fill: parent
          onClicked: {
                  model.append({text: "Click"});
          }
      }
      

      }

      @

      157

      1 Reply Last reply
      1
      • W Offline
        W Offline
        wshn14
        wrote on last edited by
        #3

        thanks but still no message output
        [quote author="p3c0" date="1382354266"]Hi,

        You need to move the signal onAdd into the delegate. Also as per "this":https://bugreports.qt-project.org/browse/QTBUG-29384 bug report i modified your code as follows and the signal gets fired
        @
        import QtQuick 2.0

        ListView
        {
        id: listView
        width:200
        height:800

        ListModel
        {
            id:listmodel
            ListElement{
                text:'text1'
            }
            ListElement{
                text:'text2'
            }
        }
        
        delegate: Rectangle {
            Text { text:model.text }
        
            ListView.onAdd: {
                console.log("ad")
            }
        }
        
        model:listmodel
        
        MouseArea {
            anchors.fill: parent
            onClicked: {
                    model.append({text: "Click"});
            }
        }
        

        }

        @[/quote]

        [quote author="p3c0" date="1382354266"]Hi,

        You need to move the signal onAdd into the delegate. Also as per "this":https://bugreports.qt-project.org/browse/QTBUG-29384 bug report i modified your code as follows and the signal gets fired
        @
        import QtQuick 2.0

        ListView
        {
        id: listView
        width:200
        height:800

        ListModel
        {
            id:listmodel
            ListElement{
                text:'text1'
            }
            ListElement{
                text:'text2'
            }
        }
        
        delegate: Rectangle {
            Text { text:model.text }
        
            ListView.onAdd: {
                console.log("ad")
            }
        }
        
        model:listmodel
        
        MouseArea {
            anchors.fill: parent
            onClicked: {
                    model.append({text: "Click"});
            }
        }
        

        }

        @[/quote]

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Hi,

          It works for me. Did you get any errors ?
          Did you click on the list ? As i have added that message when one click's on the List.
          @
          MouseArea {
          anchors.fill: parent
          onClicked: {
          model.append({text: "Click"});
          }
          }
          @

          And message is here in
          @
          ListView.onAdd: {
          console.log("ad")
          }
          @

          157

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wshn14
            wrote on last edited by
            #5

            I think the message 'ad' should output even if I don't click ,because the connected signal is onAdd but not onClick ,is that right?
            [quote author="p3c0" date="1382356560"]Hi,

            It works for me. Did you get any errors ?
            Did you click on the list ? As i have added that message when one click's on the List.
            @
            MouseArea {
            anchors.fill: parent
            onClicked: {
            model.append({text: "Click"});
            }
            }
            @

            And message is here in
            @
            ListView.onAdd: {
            console.log("ad")
            }
            @[/quote]

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Ever
              wrote on last edited by
              #6

              Try to add x property to delegate so you can see better:

              @delegate: Rectangle {
              x: model.index * 50

                  Text { text:model.text }
              
                  ListView.onAdd: {
                      console.log("ad")
                  }
              }@
              

              The roots of education are bitter, but the fruit is sweet.

              1 Reply Last reply
              0
              • W Offline
                W Offline
                wshn14
                wrote on last edited by
                #7

                still not 'ad' output
                [quote author="Ever" date="1382423093"]Try to add x property to delegate so you can see better:

                @delegate: Rectangle {
                x: model.index * 50

                    Text { text:model.text }
                
                    ListView.onAdd: {
                        console.log("ad")
                    }
                }@[/quote]
                
                1 Reply Last reply
                0

                • Login

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