From f6870581e45c1290a43472a1ed0685f87ac4723e Mon Sep 17 00:00:00 2001 From: Aurindam Jana <aurindam.jana@nokia.com> Date: Wed, 29 Feb 2012 09:50:34 +0100 Subject: [PATCH] ScriptConsole: Crash FIX Disconnect signals and slots when resetting QtMessageLogHandler. Change-Id: I1a034c302b8e06f32b4bb2c5eaecae71488c5062 Reviewed-by: Kai Koehne <kai.koehne@nokia.com> --- src/plugins/debugger/qtmessagelogwindow.cpp | 53 ++++++++++++++------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/src/plugins/debugger/qtmessagelogwindow.cpp b/src/plugins/debugger/qtmessagelogwindow.cpp index 05eb5661e91..3be4b73af61 100644 --- a/src/plugins/debugger/qtmessagelogwindow.cpp +++ b/src/plugins/debugger/qtmessagelogwindow.cpp @@ -211,22 +211,43 @@ void QtMessageLogWindow::writeSettings() const void QtMessageLogWindow::setModel(QAbstractItemModel *model) { - m_proxyModel->setSourceModel(model); - QtMessageLogHandler *handler = qobject_cast<QtMessageLogHandler *>(model); - m_itemDelegate->setItemModel(handler); - connect(m_clearAction, SIGNAL(triggered()), handler, SLOT(clear())); - connect(handler, - SIGNAL(selectEditableRow(QModelIndex,QItemSelectionModel::SelectionFlags)), - m_proxyModel, - SLOT(selectEditableRow(QModelIndex,QItemSelectionModel::SelectionFlags))); - - //Scroll to bottom when rows matching current filter settings are inserted - //Not connecting rowsRemoved as the only way to remove rows is to clear the - //model which will automatically reset the view. - connect(handler, - SIGNAL(rowsInserted(QModelIndex,int,int)), - m_proxyModel, - SLOT(onRowsInserted(QModelIndex,int,int))); + QtMessageLogHandler *oldHandler = qobject_cast<QtMessageLogHandler *>( + m_proxyModel->sourceModel()); + if (oldHandler) { + disconnect(m_clearAction, SIGNAL(triggered()), oldHandler, SLOT(clear())); + disconnect(oldHandler, + SIGNAL(selectEditableRow( + QModelIndex,QItemSelectionModel::SelectionFlags)), + m_proxyModel, + SLOT(selectEditableRow( + QModelIndex,QItemSelectionModel::SelectionFlags))); + disconnect(oldHandler, + SIGNAL(rowsInserted(QModelIndex,int,int)), + m_proxyModel, + SLOT(onRowsInserted(QModelIndex,int,int))); + } + + QtMessageLogHandler *newHandler = qobject_cast<QtMessageLogHandler *>(model); + m_proxyModel->setSourceModel(newHandler); + m_itemDelegate->setItemModel(newHandler); + + if (newHandler) { + connect(m_clearAction, SIGNAL(triggered()), newHandler, SLOT(clear())); + connect(newHandler, + SIGNAL(selectEditableRow( + QModelIndex,QItemSelectionModel::SelectionFlags)), + m_proxyModel, + SLOT(selectEditableRow( + QModelIndex,QItemSelectionModel::SelectionFlags))); + + //Scroll to bottom when rows matching current filter settings are inserted + //Not connecting rowsRemoved as the only way to remove rows is to clear the + //model which will automatically reset the view. + connect(newHandler, + SIGNAL(rowsInserted(QModelIndex,int,int)), + m_proxyModel, + SLOT(onRowsInserted(QModelIndex,int,int))); + } } } // namespace Internal -- GitLab