diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index c9d74ce2c..3b504b951 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -1484,9 +1484,28 @@ void QupZilla::closeEvent(QCloseEvent* event) } #endif + disconnectAllWidgets(); event->accept(); } +void QupZilla::disconnectAllWidgets() +{ + // Disconnecting all important widgets before deleting this window + // so it cannot happen that slots will be invoked after the object + // is deleted. + // We have to do it this way, because ~QObject is deleting all child + // objects with plain delete - not deleteLater(). + + disconnect(); + m_tabWidget->disconnect(); + m_tabWidget->getTabBar()->disconnect(); + + foreach(WebTab * tab, m_tabWidget->allTabs()) { + WebView* view = tab->view(); + view->disconnect(); + } +} + bool QupZilla::quitApp() { if (m_sideBar.data()) { diff --git a/src/app/qupzilla.h b/src/app/qupzilla.h index 6354b4efe..6b81dff8a 100644 --- a/src/app/qupzilla.h +++ b/src/app/qupzilla.h @@ -210,9 +210,10 @@ private: void setupUi(); void setupMenu(); - void addSideBar(); + void disconnectAllWidgets(); + bool m_historyMenuChanged; bool m_bookmarksMenuChanged; bool m_isClosing; diff --git a/src/webview/tabwidget.cpp b/src/webview/tabwidget.cpp index ecbe98533..63d3b20fe 100644 --- a/src/webview/tabwidget.cpp +++ b/src/webview/tabwidget.cpp @@ -354,6 +354,7 @@ void TabWidget::closeTab(int index) tabBar()->setVisible(false); } + widget(index)->disconnect(); widget(index)->deleteLater(); } diff --git a/src/webview/webview.cpp b/src/webview/webview.cpp index 8fb480e62..ce31a3f5b 100644 --- a/src/webview/webview.cpp +++ b/src/webview/webview.cpp @@ -388,6 +388,9 @@ TabWidget* WebView::tabWidget() const return 0; } +// FIXME: Don't do this magic to get index of tab. +// Implement setTabIndex() and call it from TabWidget (when creating and also from +// tabMoved slot) int WebView::tabIndex() const { TabWidget* tabWid = tabWidget(); @@ -396,7 +399,10 @@ int WebView::tabIndex() const } int i = 0; - while (qobject_cast(tabWid->widget(i))->view() != this) { + while (WebTab* wTab = qobject_cast(tabWid->widget(i))) { + if (wTab && wTab->view() == this) { + break; + } i++; } return i; @@ -1103,4 +1109,5 @@ bool WebView::eventFilter(QObject* obj, QEvent* event) WebView::~WebView() { + m_page->triggerAction(QWebPage::Stop); }