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

Bug in QListWidget::row

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.6
    • Widgets: Itemviews
    • None
    • All

    Description

      I often need to check if QListWidgetItem* exists in the QListWidget. The current method I can use is QListWidget::row. But if the Item has already been destroyed, the pointer passing into the row will cause the program to crash.

      QListWidget::row(QTreeWidgetItem*) → QListModel::index(QTreeWidgetItem*)

      Obviously, the current row function does not take into account that the item has been destroyed.

      The red part of the screenshot can be modified:
      if(!item||items.isEmpty||!items.contains(item))return QModelIndex();

      Because when the item is no longer in the Widget, it often means that it may have been deleted, so you can avoid the crash of the item->view.

      Provided a Qt6.6-based Demo,Program crashes don't have to happen, but they do have a certain probability.

      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
            298218699 298218699
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes