0

can anyone please help me to set the cookies in a webview in BB10

below is my trial but it's not working

in 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);

}
Wanna Coffee
  • 2,742
  • 7
  • 40
  • 66
Zak
  • 571
  • 2
  • 6
  • 13

1 Answers1

2

You can set it directly from QML:

webView.storage.cookieJar.setCookiesFromUrl(webView.url, ["test=test", "test1=test1"]);
mishod
  • 1,040
  • 1
  • 10
  • 21