From 6a905d38d96572867db42a17f623e3917cf5063f Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Tue, 2 May 2023 11:26:21 -0400 Subject: [PATCH] Update the right index when removing. --- chatlistmodel.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/chatlistmodel.h b/chatlistmodel.h index 0c7b85c4..20c6eeba 100644 --- a/chatlistmodel.h +++ b/chatlistmodel.h @@ -99,7 +99,9 @@ public: Q_ASSERT(nextChat); setCurrentChat(nextChat); } - beginRemoveRows(QModelIndex(), index, index); + + const int newIndex = m_chats.indexOf(chat); + beginRemoveRows(QModelIndex(), newIndex, newIndex); m_chats.removeAll(chat); endRemoveRows(); delete chat; @@ -167,6 +169,15 @@ private Q_SLOTS: emit dataChanged(index, index, {NameRole}); } + void printChats() + { + for (auto c : m_chats) { + qDebug() << c->name() + << (c == m_currentChat ? "currentChat: true" : "currentChat: false") + << (c == m_newChat ? "newChat: true" : "newChat: false"); + } + } + private: Chat* m_newChat; Chat* m_currentChat;