diff --git a/src/plugins/debugger/qtmessagelogwindow.cpp b/src/plugins/debugger/qtmessagelogwindow.cpp index 05eb5661e910b6227037fd36a42e812bd1724268..3be4b73af61f6a4ce33e3200d3d700e4e907211a 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