diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 483db2098..9bc7e4866 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -133,7 +133,14 @@ void MainWindow::disconnectController(SessionController* controller) { disconnect( controller , SIGNAL(titleChanged(ViewProperties*)) , this , SLOT(activeViewTitleChanged(ViewProperties*)) ); - guiFactory()->removeClient(controller); + + // KXmlGuiFactory::removeClient() will try to access actions associated + // with the controller internally, which may not be valid after the controller + // itself is no longer valid (after the associated session and or view have + // been destroyed) + if (controller->isValid()) + guiFactory()->removeClient(controller); + controller->setSearchBar(0); } diff --git a/src/SessionController.h b/src/SessionController.h index cc9e356cc..fad71e9f0 100644 --- a/src/SessionController.h +++ b/src/SessionController.h @@ -95,6 +95,14 @@ public: QPointer session() { return _session; } /** Returns the view associated with this controller */ QPointer view() { return _view; } + + /** + * Returns true if the controller is valid. + * A valid controller is one which has a non-null session() and view(). + * + * Equivalent to "!session().isNull() && !view().isNull()" + */ + bool isValid() const; /** * Sets the widget used for searches through the session's output. @@ -250,6 +258,10 @@ private: bool _listenForScreenWindowUpdates; bool _preventClose; }; +inline bool SessionController::isValid() const +{ + return !_session.isNull() && !_view.isNull(); +} /** * Abstract class representing a task which can be performed on a group of sessions.