Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-68232

ListView should emit currentIndexChanged -1 on setting empty model

    XMLWordPrintable

Details

    • db321e74413ac088edaa209a57ad5147175df041 (qt/qtdeclarative/5.14)

    Description

      Had ListView with QList<QObject*> model. Let say user ask to delete currently selected object. Apps delete object, update model and set currentIndex to -1. Everything alright, onCurrentIndexChanged is printing info about setting currentIndex to -1:

      onCurrentIndexChanged: console.log("currentIndex" + currentIndex)
      

      But if the object was the last object and updated model is become empty, Qt automatically set currentIndex of ListView to -1 without emitting CurrentIndexChanged. And setting currentIndex -1 in app does nothing, because it is already -1!
      So all bindings with currentIndex will not be updated in this case:

      enabled: idList.currentIndex >= 0
      

      I suppose that ListView should emit currentIndexChanged -1 in this case.

      For now in places where currentIndex is needed a workaround is to check with currentIndex also model.length.

      enabled: ((idList.model.length > 0) && (idList.currentIndex >= 0))
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            lukegluke Oleg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes