任何人都可以帮我在BB10的webview中设置cookie
以下是我的试用版,但它无效
在qml中
WebView {
id: webview
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
preferredWidth: 700
settings.javaScriptEnabled: true
settings.imageDownloadingEnabled: true
settings.webInspectorEnabled: true
url: constants.GET_BASEURL_Value() + subCatValue
onCreationCompleted: {
app.setWebCookies(webview, constants.GET_BASEURL_Value() + subCatValue);
}
preferredHeight: 1100
}
in cpp
void ApplicationUI::setWebCookies(QObject* webObject, QString urlString) const {
WebView* webview = qobject_cast<WebView*>(webObject);
QUrl url = QUrl(urlString);
WebCookieJar* m_pWebCookieJar = (webview->storage())->cookieJar();
QSettings settings;
QStringList cookies;
cookies << "Cookie=" << settings.value("JSONID", "").toString().toUtf8();
m_pWebCookieJar->setCookiesFromUrl(url, cookies);
QStringList cookiesFromJar = m_pWebCookieJar->cookiesForUrl(url);
}
答案 0 :(得分:2)
您可以直接从QML设置它:
webView.storage.cookieJar.setCookiesFromUrl(webView.url, ["test=test", "test1=test1"]);