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){ void ArticleNetworkAccessManager:: requestStart(QUrl& url){
QNetworkRequest request; // QNetworkRequest request;
request.setUrl( url ); // request.setUrl( url );
QNetworkReply* reply = createRequest(QNetworkAccessManager::GetOperation,request,NULL); // QNetworkReply* reply = createRequest(QNetworkAccessManager::GetOperation,request,NULL);
} }
sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource( sptr< Dictionary::DataRequest > ArticleNetworkAccessManager::getResource(
@ -542,19 +542,26 @@ void BlockedNetworkReply::finishedSlot()
emit finished(); emit finished();
} }
MySchemeHandler::MySchemeHandler(){ MySchemeHandler::MySchemeHandler(ArticleNetworkAccessManager& articleNetMgr):mManager(articleNetMgr){
} }
void MySchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob) void MySchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
{ {
QUrl url = requestJob->requestUrl(); QUrl url = requestJob->requestUrl();
// QNetworkRequest* request = new QNetworkRequest(url);
QNetworkRequest request;
request.setUrl( url );
// Reply segment QNetworkReply* reply=this->mManager.createRequest(QNetworkAccessManager::GetOperation,request,NULL);
// requestJob->reply("text/html", reply); 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 Q_OBJECT
public: public:
MySchemeHandler(); MySchemeHandler(ArticleNetworkAccessManager &articleNetMgr);
void requestStarted(QWebEngineUrlRequestJob *requestJob); void requestStarted(QWebEngineUrlRequestJob *requestJob);
protected: protected:
signals: signals:
void requestStart(QUrl& url); void requestStart(QUrl& url);
private:
ArticleNetworkAccessManager& mManager;
}; };
#endif #endif

View file

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