From 5ec3a2db85dd1c69a21989fd096a3c154c4a567c Mon Sep 17 00:00:00 2001 From: krepa098 Date: Sun, 8 Feb 2015 10:11:55 +0100 Subject: [PATCH] Fix ownership problem (issue #8) --- src/chatlog/chatlog.cpp | 11 +++++++++++ src/chatlog/chatlog.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 979ba0c38..4d3698cac 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -99,6 +99,17 @@ ChatLog::ChatLog(QWidget* parent) connect(workerTimer, &QTimer::timeout, this, &ChatLog::onWorkerTimeout); } +ChatLog::~ChatLog() +{ + // Drop ownership of items of type ChatLineContentType + // as they are owned by ChatLine + for(QGraphicsItem* item : items()) + { + if(item->type() == ChatLineContent::ChatLineContentType) + scene->removeItem(item); + } +} + void ChatLog::clearSelection() { if(selectionMode == None) diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index ffc1bf876..0ab495e4d 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -36,6 +36,7 @@ class ChatLog : public QGraphicsView Q_OBJECT public: explicit ChatLog(QWidget* parent = 0); + virtual ~ChatLog(); void insertChatlineAtBottom(ChatLine::Ptr l); void insertChatlineOnTop(ChatLine::Ptr l);