我想通過QnetworkRequest到位於我的main.qml文件而不是「url」的webView。我通過引用webView對象和setproperty函數來傳遞url。但是,沒有找到正確的功能,真的不知道從哪裏開始,以便創建一個新功能或修改現有的webView代碼,以使其發揮作用。有沒有辦法在.qml文件中編輯webView的源代碼。當然,我只是在學習QT框架。QT 5.8 Webview如何執行請求以及如何攔截它?
我已經嘗試過WebengineView,但Webview加載頁面的速度更快。這對於應用程序是至關重要的
我想真正的問題是Webview如何執行請求以及如何攔截它?
main.qml
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtWebView 1.1
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
ApplicationWindow {
flags: Qt.FramelessWindowHint
visible: true
x: 600
y: 400
width: 500
height: 500
title: webView.title
WebView {
id: webView
anchors.fill: parent
objectName: "webView"
//setting this value through main.cpp
// url: "https://www.google.com"
onLoadingChanged: {
if (loadRequest.errorString)
console.error(loadRequest.errorString);
}
}
}
的main.cpp
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtWebView::initialize();
QQmlApplicationEngine engine;
//How to Pass THIS request to the webview instead of url?
QNetworkRequest request;
request.setUrl(QUrl("http://google.com"));
request.setRawHeader("Accept-Charset", "UTF-8,*;q=0.5");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QObject *rootObject = engine.rootObjects().first();
QObject *qmlObject = rootObject->findChild<QObject*>("webView");
//Able to set the URL for the webView:
qmlObject->setProperty("url", "https://www.google.com");
return app.exec();
}
如何改變URL從QML時'''的''url'''財產的處理'WebView'''改變? '''onUrlChanged:{...}''' –