diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-02-27 16:02:49 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-02-27 16:02:49 +0100 |
commit | 5b75e14696c9d0452e6e393b61ccf74399665d64 (patch) | |
tree | 1d579e0799fe773fd978519669703b741f77438f /src | |
parent | installing config file (diff) | |
download | smolbote-5b75e14696c9d0452e6e393b61ccf74399665d64.tar.xz |
Fixed crash when closing the first tab
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.cpp | 2 | ||||
-rw-r--r-- | src/widgets/webviewtabbar.cpp | 13 | ||||
-rw-r--r-- | src/widgets/webviewtabbar.h | 7 |
3 files changed, 14 insertions, 8 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 30751d5..18c1e14 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -203,6 +203,8 @@ void MainWindow::handleNewWindow(const QUrl &url) void MainWindow::handleTabChanged(WebView *view) { + Q_ASSERT(view); + // clear the parent of the central widget so it doesn't get deleted centralWidget()->setParent(0); 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); |