diff options
author | Kevin Smith <git@kismith.co.uk> | 2011-05-13 19:37:33 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2011-05-13 19:38:14 (GMT) |
commit | 0b9db0c080dbfeef6d209544afcc120712ab445e (patch) | |
tree | 42ad56a07e0cf1d25523cfbe0c4d1c84f57c18a0 /Swift/QtUI/QtUIFactory.cpp | |
parent | 57c0d20400e162b90050e72702f65cad37c12ead (diff) | |
download | swift-contrib-0b9db0c080dbfeef6d209544afcc120712ab445e.zip swift-contrib-0b9db0c080dbfeef6d209544afcc120712ab445e.tar.bz2 |
Don't crash when chat windows are deleted.
Resolves: #879
Diffstat (limited to 'Swift/QtUI/QtUIFactory.cpp')
-rw-r--r-- | Swift/QtUI/QtUIFactory.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp index ffbe3c0..40ce95e 100644 --- a/Swift/QtUI/QtUIFactory.cpp +++ b/Swift/QtUI/QtUIFactory.cpp @@ -86,12 +86,19 @@ MUCSearchWindow* QtUIFactory::createMUCSearchWindow() { ChatWindow* QtUIFactory::createChatWindow(const JID& contact, UIEventStream* eventStream) { QtChatWindow* window = dynamic_cast<QtChatWindow*>(chatWindowFactory->createChatWindow(contact, eventStream)); chatWindows.push_back(window); - foreach (QtChatWindow* existingWindow, chatWindows) { - connect(window, SIGNAL(fontResized(int)), existingWindow, SLOT(handleFontResized(int))); - connect(existingWindow, SIGNAL(fontResized(int)), window, SLOT(handleFontResized(int))); + std::vector<QPointer<QtChatWindow> > deletions; + foreach (QPointer<QtChatWindow> existingWindow, chatWindows) { + if (existingWindow.isNull()) { + deletions.push_back(existingWindow); + } else { + connect(window, SIGNAL(fontResized(int)), existingWindow, SLOT(handleFontResized(int))); + connect(existingWindow, SIGNAL(fontResized(int)), window, SLOT(handleFontResized(int))); + } + } + foreach (QPointer<QtChatWindow> deletedWindow, deletions) { + chatWindows.erase(std::remove(chatWindows.begin(), chatWindows.end(), deletedWindow), chatWindows.end()); } connect(window, SIGNAL(fontResized(int)), this, SLOT(handleChatWindowFontResized(int))); - connect(window, SIGNAL(destroyed(QObject*)), this, SLOT(handleChatWindowDestroyed(QObject*))); window->handleFontResized(chatFontSize); return window; } @@ -101,11 +108,6 @@ void QtUIFactory::handleChatWindowFontResized(int size) { settings->storeInt(CHATWINDOW_FONT_SIZE, size); } -void QtUIFactory::handleChatWindowDestroyed(QObject* window) { - QtChatWindow* chatWindow = qobject_cast<QtChatWindow*>(window); - chatWindows.erase(std::remove(chatWindows.begin(), chatWindows.end(), chatWindow), chatWindows.end()); -} - UserSearchWindow* QtUIFactory::createUserSearchWindow(UserSearchWindow::Type type, UIEventStream* eventStream, const std::set<std::string>& groups) { return new QtUserSearchWindow(eventStream, type, groups); }; |