From 1cd1be84a1aeb456e7bccfce38258279a1b78b3b Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Wed, 14 Sep 2022 20:01:01 +0800 Subject: [PATCH] "opt:website dictionary display when http status!=200" --- iframeschemehandler.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/iframeschemehandler.cpp b/iframeschemehandler.cpp index cab5c7f9..d0e1363a 100644 --- a/iframeschemehandler.cpp +++ b/iframeschemehandler.cpp @@ -23,12 +23,21 @@ void IframeSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob) QByteArray contentType = "text/html"; QBuffer * buffer = new QBuffer( requestJob ); - // Handle reply data + QByteArray replyData = reply->readAll(); QString articleString; QTextCodec * codec = QTextCodec::codecForHtml( replyData, QTextCodec::codecForName( "UTF-8" ) ); articleString = codec->toUnicode( replyData ); + // Handle reply data + // 404 response may have response body. + if( reply->error() != QNetworkReply::NoError && articleString.isEmpty()) + { + QString emptyHtml = QString( "%1" ).arg( reply->errorString() ); + buffer->setData( emptyHtml.toUtf8() ); + requestJob->reply( contentType, buffer ); + return; + } // Change links from relative to absolute