From 5b75e14696c9d0452e6e393b61ccf74399665d64 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Mon, 27 Feb 2017 16:02:49 +0100 Subject: Fixed crash when closing the first tab --- src/widgets/webviewtabbar.cpp | 13 ++++++++----- src/widgets/webviewtabbar.h | 7 ++++--- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp index fa8a0e8..c482eb3 100644 --- a/src/widgets/webviewtabbar.cpp +++ b/src/widgets/webviewtabbar.cpp @@ -28,7 +28,7 @@ WebViewTabBar::WebViewTabBar(QWidget *parent) : setElideMode(Qt::ElideRight); setTabsClosable(true); setMovable(true); - connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(handleTabClose(int))); + connect(this, SIGNAL(tabCloseRequested(int)), this, SLOT(removeTab(int))); connect(this, SIGNAL(currentChanged(int)), this, SLOT(handleCurrentChanged(int))); connect(this, SIGNAL(tabMoved(int,int)), this, SLOT(updateVectorArrangement(int,int))); @@ -36,7 +36,7 @@ WebViewTabBar::WebViewTabBar(QWidget *parent) : QAction *tabCloseAction = new QAction(this); tabCloseAction->setShortcut(QKeySequence::fromString(sSettings->value("window.shortcuts.tabClose").toString())); connect(tabCloseAction, &QAction::triggered, [this]() { - this->handleTabClose(currentIndex()); + this->removeTab(currentIndex()); }); addAction(tabCloseAction); } @@ -111,12 +111,15 @@ void WebViewTabBar::handleCurrentChanged(int index) emit currentTabChanged(m_views.at(index)); } -void WebViewTabBar::handleTabClose(int index) +void WebViewTabBar::removeTab(int index) { - qDebug("removing tab %i", index); - removeTab(index); + // remove the tab data from the index m_views.at(index)->deleteLater(); m_views.remove(index); + + // remove the tab from the QTabBar + // this emits the currentTabChanged signal, so it should be done after the view is removed from the index + QTabBar::removeTab(index); } void WebViewTabBar::updateTabText(WebView *view, const QString &text) diff --git a/src/widgets/webviewtabbar.h b/src/widgets/webviewtabbar.h index 9029bf5..91e55d0 100644 --- a/src/widgets/webviewtabbar.h +++ b/src/widgets/webviewtabbar.h @@ -32,20 +32,21 @@ public: WebViewTabBar(QWidget *parent = 0); ~WebViewTabBar(); - int addTab(QWebEngineProfile *profile, const QUrl &url); void setProfile(QWebEngineProfile *profile); - WebView *currentView(); signals: void currentTabChanged(WebView *view); +public slots: + int addTab(QWebEngineProfile *profile, const QUrl &url); + void removeTab(int index); + protected: QSize tabSizeHint(int index) const; private slots: void handleCurrentChanged(int index); - void handleTabClose(int index); void updateTabText(WebView *view, const QString &text); void updateVectorArrangement(int from, int to); -- cgit v1.2.1