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. Problems with using Loader as delegate of ListView
Forum Updated to NodeBB v4.3 + New Features

Problems with using Loader as delegate of ListView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.5k 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.
  • F Offline
    F Offline
    FOXLISIN
    wrote on last edited by FOXLISIN
    #1

    Hi to all! I faced with the next problem with a ListView - when i scroll a list out the bounds a have the next errors (warnings?), but all displays in application correctly:

    qrc:/Resources/qml/TitledMessage.qml:62: TypeError: Cannot read property 'DisplayRole' of null
    
    qrc:/Resources/qml/UntitledMessage.qml:32: TypeError: Cannot read property 'DisplayRole' of null
    

    Here is my ListView:

    ListView {
        id: chatView;
    
        spacing: dp(20);
    
        model: applicationBridge.chatModel;
    
        delegate: Loader {
            property variant modelData: model;
            width: chatView.width;
            sourceComponent: applicationBridge.toDrawMessageHeader( index ) ? titledMessage : untitledMessage;
        }
    
        Component {
            id: titledMessage;
            TitledMessage {}
        }
    
        Component {
            id: untitledMessage;
            UntitledMessage {}
        }
    }
    

    and i use modelData.DisplayRole to display some text in my TitledMessage {} and UntitledMessage {}.

    I tryed to call console.log( modelData.DisplayRole ) in Component.onDestruction of my TitledMessage {} and i see in the log next:

    qrc:/Resources/qml/TitledMessage.qml:84: ReferenceError: modelData is not defined
    

    What wrong with my code? I cant't fix it. Thank you in advance.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      FOXLISIN
      wrote on last edited by
      #2

      Someone faced with the same problem?

      1 Reply Last reply
      0
      • L Offline
        L Offline
        literA2
        wrote on last edited by literA2
        #3

        @FOXLISIN based on my understanding, you tried to display/log modelData.DisplayRole in your Loader sources: TitledMessage {} and UntitledMessage {}. You are getting such error that modelData is not defined because it (modelData) will only be accessible in the Loader or on the ListView not on its sources. If you wanted to display something in either TitledMessage {} and UntitledMessage {}, you need to use console.log(model.propertyName). Please be advised that property name is case sensitive.

        I hope this helps.

        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