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. Error in ItemDelegate
QtWS25 Last Chance

Error in ItemDelegate

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 1.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.
  • adonisQt97A Offline
    adonisQt97A Offline
    adonisQt97
    wrote on last edited by
    #1

    Hi every one i am doing the QML tutorial "chat application" and i got and error on this code :

     ListView {
                id: listView
                anchors.fill: parent
                topMargin: 48
                leftMargin: 48
                bottomMargin: 48
                rightMargin: 48
                spacing: 20
                model: ["Albert Einstein", "Ernest Hemingway", "Hans Gude"]
                ItemDelegate{
                    text: modelData
                    width: listView.width - listView.leftMargin - listView.rightMargin
                    height: avatar.implicitHeight
                    leftPadding: avatar.implicitWidth + 32
    
                    Image {
                        id: avatar
                        source: "qrc:/:/../../../Téléchargements/material-design-icons-master/action/1x_web/ic_account_circle_white_48dp.png"
                    }
              
    

    The error is

    qrc:/main.qml:40: ReferenceError: modelData is not defined
    

    I don't know how to correct it. Thanks in advance

    E 1 Reply Last reply
    0
    • adonisQt97A adonisQt97

      Hi every one i am doing the QML tutorial "chat application" and i got and error on this code :

       ListView {
                  id: listView
                  anchors.fill: parent
                  topMargin: 48
                  leftMargin: 48
                  bottomMargin: 48
                  rightMargin: 48
                  spacing: 20
                  model: ["Albert Einstein", "Ernest Hemingway", "Hans Gude"]
                  ItemDelegate{
                      text: modelData
                      width: listView.width - listView.leftMargin - listView.rightMargin
                      height: avatar.implicitHeight
                      leftPadding: avatar.implicitWidth + 32
      
                      Image {
                          id: avatar
                          source: "qrc:/:/../../../Téléchargements/material-design-icons-master/action/1x_web/ic_account_circle_white_48dp.png"
                      }
                
      

      The error is

      qrc:/main.qml:40: ReferenceError: modelData is not defined
      

      I don't know how to correct it. Thanks in advance

      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @adonisQt97 I opened the Qt Quick Control 2 - Chat Tutorial, built subproject chapter2-lists and it runs well. We need more info about your setup. Creator version, Qt version, OS etc. And how you compile and run it.

      adonisQt97A 1 Reply Last reply
      0
      • jpnurmiJ Offline
        jpnurmiJ Offline
        jpnurmi
        wrote on last edited by
        #3

        The item delegate should be assigned to ListView::delegate:

        ListView {
            ...
            delegate: ItemDelegate {
                ...
            }
        }
        
        adonisQt97A 1 Reply Last reply
        4
        • E Eeli K

          @adonisQt97 I opened the Qt Quick Control 2 - Chat Tutorial, built subproject chapter2-lists and it runs well. We need more info about your setup. Creator version, Qt version, OS etc. And how you compile and run it.

          adonisQt97A Offline
          adonisQt97A Offline
          adonisQt97
          wrote on last edited by
          #4

          @Eeli-K | I am redoing it by following the tutorial !!

          1 Reply Last reply
          0
          • jpnurmiJ jpnurmi

            The item delegate should be assigned to ListView::delegate:

            ListView {
                ...
                delegate: ItemDelegate {
                    ...
                }
            }
            
            adonisQt97A Offline
            adonisQt97A Offline
            adonisQt97
            wrote on last edited by
            #5

            @jpnurmi thank you it work well

            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