mirror of
https://github.com/quickshell-mirror/quickshell.git
synced 2026-10-27 02:54:36 +00:00
core/scriptmodel: detatch mValues when accessed during update
Fixes iterator invalidation caused by the QML engine.
This commit is contained in:
2 files changed
+11
-1
No files matched your search
@@ -12,6 +12,7 @@
|
||||
#include <qvariant.h>
|
||||
|
||||
void ScriptModel::updateValuesUnique(const QVariantList& newValues) {
|
||||
this->hasActiveIterators = true;
|
||||
this->mValues.reserve(newValues.size());
|
||||
|
||||
auto iter = this->mValues.begin();
|
||||
@@ -112,6 +113,8 @@ void ScriptModel::updateValuesUnique(const QVariantList& newValues) {
|
||||
++newIter;
|
||||
}
|
||||
}
|
||||
|
||||
this->hasActiveIterators = false;
|
||||
}
|
||||
|
||||
void ScriptModel::setValues(const QVariantList& newValues) {
|
||||
|
||||
@@ -70,7 +70,13 @@ class ScriptModel: public QAbstractListModel {
|
||||
QML_ELEMENT;
|
||||
|
||||
public:
|
||||
[[nodiscard]] const QVariantList& values() const { return this->mValues; }
|
||||
[[nodiscard]] QVariantList values() const {
|
||||
auto values = this->mValues;
|
||||
// If not detached, the QML engine will invalidate iterators in updateValuesUnique.
|
||||
if (this->hasActiveIterators) values.detach();
|
||||
return values;
|
||||
}
|
||||
|
||||
void setValues(const QVariantList& newValues);
|
||||
|
||||
[[nodiscard]] qint32 rowCount(const QModelIndex& parent) const override;
|
||||
@@ -82,6 +88,7 @@ signals:
|
||||
|
||||
private:
|
||||
QVariantList mValues;
|
||||
bool hasActiveIterators = false;
|
||||
|
||||
void updateValuesUnique(const QVariantList& newValues);
|
||||
};
|
||||
Reference in new issue
Block a user