Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

modelData and ListView



  • I have this ListView{} element and inside of it there is Component with a title property. For that title they have modelData.label set:

    ListView
    {
     ...
      Banner
      {
        title: modelData.label
      }
    }
    

    Can I assume that modelData is reffering to the ListView's model property? When I right click the modelData.label and select: "Follow symbol under cursor" it takes me nowhere. The actual model property for the ListView is being set to some value in the business logic.

    I guess what I am trying to ask is, if I create a ListView can I refer to it as modelData or is it a bad idea for me to assume that this modelData belongs to it's parent ListView?



  • It depends on your model. From:

    https://doc.qt.io/qt-5/qtquick-modelviewsdata-modelview.html

    Models that do not have named roles will have the data provided via the modelData role. The modelData role is also provided for models that have only one role. In this case the modelData role contains the same data as the named role.

    If your model has roles, you could use just the role name, "label", or "model.label" to avoid ambiguity.



  • @Leonardo Okay well this particular ListView has this model:

    model: presentationManager.settingsPresenter.propertiesForDevice
    

    I checked and propertiesForDevice() is defined as:

    QList<QObject*> propertiesDevice();
    

Log in to reply