diff --git a/src/corelib/itemmodels/qgenericitemmodel.h b/src/corelib/itemmodels/qgenericitemmodel.h index 3c6e2aeb1c8..05941f4a890 100644 --- a/src/corelib/itemmodels/qgenericitemmodel.h +++ b/src/corelib/itemmodels/qgenericitemmodel.h @@ -240,13 +240,19 @@ public: // we didn't remove the const of the range first. const_row_reference row = rowData(index); row_reference mutableRow = const_cast(row); - for_element_at(mutableRow, index.column(), [&f](auto &&ref){ - using target_type = decltype(ref); - if constexpr (std::is_const_v>) - f &= ~Qt::ItemIsEditable; - else if constexpr (std::is_lvalue_reference_v) - f |= Qt::ItemIsEditable; - }); + if (QGenericItemModelDetails::isValid(mutableRow)) { + for_element_at(mutableRow, index.column(), [&f](auto &&ref){ + using target_type = decltype(ref); + if constexpr (std::is_const_v>) + f &= ~Qt::ItemIsEditable; + else if constexpr (std::is_lvalue_reference_v) + f |= Qt::ItemIsEditable; + }); + } else { + // If there's no usable value stored in the row, then we can't + // do anything with this item. + f &= ~Qt::ItemIsEditable; + } } return f; }