fix:loaded url twice

This commit is contained in:
yifang 2021-09-24 20:29:13 +08:00
parent bf2640bb25
commit a23409c875
3 changed files with 22 additions and 11 deletions

View file

@ -288,9 +288,9 @@ QNetworkReply * ArticleNetworkAccessManager::createRequest( Operation op,
}
void ArticleNetworkAccessManager:: requestStart(QUrl& url){
QNetworkRequest request;
request.setUrl( url );
QNetworkReply* reply = createRequest(QNetworkAccessManager::GetOperation,request,NULL);
// QNetworkRequest request;
// request.setUrl( url );
// QNetworkReply* reply = createRequest(QNetworkAccessManager::GetOperation,request,NULL);
}
sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
@ -542,19 +542,26 @@ void BlockedNetworkReply::finishedSlot()
emit finished();
}
MySchemeHandler::MySchemeHandler(){
MySchemeHandler::MySchemeHandler(ArticleNetworkAccessManager& articleNetMgr):mManager(articleNetMgr){
}
void MySchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
{
QUrl url = requestJob->requestUrl();
// QNetworkRequest* request = new QNetworkRequest(url);
QNetworkRequest request;
request.setUrl( url );
// Reply segment
// requestJob->reply("text/html", reply);
QNetworkReply* reply=this->mManager.createRequest(QNetworkAccessManager::GetOperation,request,NULL);
connect(reply,&QNetworkReply::finished,[=](){
//QNetworkReply *reply1=qobject_cast<QNetworkReply*>(sender());
requestJob->reply("text/html",reply);
});
emit requestStart(url);
// // Reply segment
// requestJob->reply("text/html", reply);
// emit requestStart(url);
}

View file

@ -211,12 +211,15 @@ class MySchemeHandler : public QWebEngineUrlSchemeHandler
{
Q_OBJECT
public:
MySchemeHandler();
MySchemeHandler(ArticleNetworkAccessManager &articleNetMgr);
void requestStarted(QWebEngineUrlRequestJob *requestJob);
protected:
signals:
void requestStart(QUrl& url);
private:
ArticleNetworkAccessManager& mManager;
};
#endif

View file

@ -146,7 +146,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
#endif
MySchemeHandler *handler = new MySchemeHandler();
MySchemeHandler *handler = new MySchemeHandler(articleNetMgr);
QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("gdlookup", handler);
QStringList localSchemes={"gdau","gico","qrcx","bres"};
@ -1302,7 +1302,8 @@ void MainWindow::applyWebSettings()
QWebEngineSettings *defaultSettings = QWebEngineSettings::globalSettings();
defaultSettings->setAttribute(QWebEngineSettings::PluginsEnabled, cfg.preferences.enableWebPlugins);
defaultSettings->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, false);
//defaultSettings->setAttribute( QWebEngineSettings::DeveloperExtrasEnabled, true );
defaultSettings->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessRemoteUrls, true );
defaultSettings->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessFileUrls, true );
}
void MainWindow::setupNetworkCache( int maxSize )