Merge pull request #173 from mammonsama666/0313-dev

Feat:Clear cache after web searching.
This commit is contained in:
Mouse Zhang 2021-03-14 10:07:50 +08:00 committed by GitHub
commit ba393697fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -129,6 +129,7 @@ void SearchDetailView::setWebWidget(const QString& keyword)
} }
} else { } else {
m_webView = new QWebEngineView(this); m_webView = new QWebEngineView(this);
m_engineProfile = m_webView->page()->profile();
m_webView->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true); m_webView->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);
m_webView->setAttribute(Qt::WA_DeleteOnClose); m_webView->setAttribute(Qt::WA_DeleteOnClose);
m_webView->move(0, 0); m_webView->move(0, 0);
@ -136,11 +137,12 @@ void SearchDetailView::setWebWidget(const QString& keyword)
connect(m_webView,&QWebEngineView::loadFinished, this, [ = ](){ connect(m_webView,&QWebEngineView::loadFinished, this, [ = ](){
m_reload = true; m_reload = true;
if (m_engineProfile) m_engineProfile->clearHttpCache();
}); });
connect(m_webView, &QWebEngineView::urlChanged, this, [ = ](const QUrl& url) { connect(m_webView, &QWebEngineView::urlChanged, this, [ = ](const QUrl& url) {
if (m_reload) { if (m_reload) {
closeWebWidget();
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
closeWebWidget();
} }
}); });
} }

View File

@ -24,7 +24,7 @@
#include <QWidget> #include <QWidget>
#include <QWebEngineView> #include <QWebEngineView>
#include <QWebEngineSettings> #include <QWebEngineSettings>
//#include <QWebEngineProfile> #include <QWebEngineProfile>
//#include <QWebEngineUrlRequestInterceptor> //#include <QWebEngineUrlRequestInterceptor>
#include <QDesktopServices> #include <QDesktopServices>
#include "option-view.h" #include "option-view.h"
@ -91,6 +91,7 @@ private:
OptionView * m_optionView = nullptr; OptionView * m_optionView = nullptr;
QWebEngineView * m_webView = nullptr; QWebEngineView * m_webView = nullptr;
QWebEngineProfile * m_engineProfile = nullptr;
bool m_reload = false; bool m_reload = false;
QString m_currentKeyword; QString m_currentKeyword;