diff --git a/src/chatdocumenthandler.h b/src/chatdocumenthandler.h index 76136ca4d..89807f521 100644 --- a/src/chatdocumenthandler.h +++ b/src/chatdocumenthandler.h @@ -159,7 +159,7 @@ private: bool m_isEdit = false; - QQuickTextDocument *m_document; + QPointer m_document; QPointer m_room; bool completionVisible = false; diff --git a/src/roommanager.cpp b/src/roommanager.cpp index 852ca6feb..cb8d6d0be 100644 --- a/src/roommanager.cpp +++ b/src/roommanager.cpp @@ -131,9 +131,13 @@ void RoomManager::enterRoom(NeoChatRoom *room) } if (m_currentRoom && m_chatDocumentHandler) { // 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()); - m_chatDocumentHandler->setRoom(room); - m_chatDocumentHandler->document()->textDocument()->setPlainText(room->savedText()); + if (m_chatDocumentHandler->document()) { + m_currentRoom->setSavedText(m_chatDocumentHandler->document()->textDocument()->toPlainText()); + m_chatDocumentHandler->setRoom(room); + m_chatDocumentHandler->document()->textDocument()->setPlainText(room->savedText()); + } else { + m_chatDocumentHandler->setRoom(room); + } } m_lastCurrentRoom = std::exchange(m_currentRoom, room); Q_EMIT currentRoomChanged(); diff --git a/src/roommanager.h b/src/roommanager.h index 535202bbe..54b4106bb 100644 --- a/src/roommanager.h +++ b/src/roommanager.h @@ -234,5 +234,5 @@ private: QString m_arg; KConfig m_config; KConfigGroup m_lastRoomConfig; - ChatDocumentHandler *m_chatDocumentHandler; + QPointer m_chatDocumentHandler; };