Fix crash in room switching

This commit is contained in:
Tobias Fella
2023-05-15 20:57:19 +02:00
parent 5bdd67dcc1
commit dee064a758
3 changed files with 9 additions and 5 deletions

View File

@@ -159,7 +159,7 @@ private:
bool m_isEdit = false; bool m_isEdit = false;
QQuickTextDocument *m_document; QPointer<QQuickTextDocument> m_document;
QPointer<NeoChatRoom> m_room; QPointer<NeoChatRoom> m_room;
bool completionVisible = false; bool completionVisible = false;

View File

@@ -131,9 +131,13 @@ void RoomManager::enterRoom(NeoChatRoom *room)
} }
if (m_currentRoom && m_chatDocumentHandler) { if (m_currentRoom && m_chatDocumentHandler) {
// We're doing these things here because it is critical that they are switched at the same time // We're doing these things here because it is critical that they are switched at the same time
m_currentRoom->setSavedText(m_chatDocumentHandler->document()->textDocument()->toPlainText()); if (m_chatDocumentHandler->document()) {
m_chatDocumentHandler->setRoom(room); m_currentRoom->setSavedText(m_chatDocumentHandler->document()->textDocument()->toPlainText());
m_chatDocumentHandler->document()->textDocument()->setPlainText(room->savedText()); m_chatDocumentHandler->setRoom(room);
m_chatDocumentHandler->document()->textDocument()->setPlainText(room->savedText());
} else {
m_chatDocumentHandler->setRoom(room);
}
} }
m_lastCurrentRoom = std::exchange(m_currentRoom, room); m_lastCurrentRoom = std::exchange(m_currentRoom, room);
Q_EMIT currentRoomChanged(); Q_EMIT currentRoomChanged();

View File

@@ -234,5 +234,5 @@ private:
QString m_arg; QString m_arg;
KConfig m_config; KConfig m_config;
KConfigGroup m_lastRoomConfig; KConfigGroup m_lastRoomConfig;
ChatDocumentHandler *m_chatDocumentHandler; QPointer<ChatDocumentHandler> m_chatDocumentHandler;
}; };