Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
6.6
-
None
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.