Fix crash in chat list delegate destruction during model update (cherry pick from quanta/master c108d42d9c1292556fc79d48830ad90cf6815925)

This commit is contained in:
Gaelle Braud 2026-03-06 10:49:03 +01:00
parent a1b682e637
commit 5b78daf372

View file

@ -25,6 +25,8 @@
#include "model/tool/ToolModel.hpp"
#include <QSharedPointer>
#include <QTimer>
#include <linphone++/linphone.hh>
// =============================================================================
@ -71,12 +73,17 @@ void ChatList::connectItem(QSharedPointer<ChatCore> chat) {
},
Qt::SingleShotConnection);
auto dataChange = [this, chat] {
// Defer dataChanged to avoid destroying QML delegates synchronously
// during a SafeConnection::invokeToCore callback, which causes
// accessibility to access already-freed QQuickItem data (QTBUG).
QTimer::singleShot(0, this, [this, chat] {
int i = -1;
get(chat.get(), &i);
if (i != -1) {
auto modelIndex = index(i);
if (modelIndex.isValid()) emit dataChanged(modelIndex, modelIndex);
}
});
};
connect(chat.get(), &ChatCore::unreadMessagesCountChanged, this, [this, dataChange] {
dataChange();