Qt WebKit and Permanent Cookies

前端 未结 3 1208
独厮守ぢ
独厮守ぢ 2021-02-05 11:39

I have a mainwindow, in it, I have a single QWebView. I want to make a certain website (www.kdkdkkd.com for instance) cookies permanent, so each time a user closes and repopens

3条回答
  •  逝去的感伤
    2021-02-05 12:11

    You need to set your own "Cookie Jar".

    1. Use QNetworkAccessManager::setCookieJar .
    2. Extend QNetworkCookieJar - as it doesn't persist cookies by default when browser is closed:

    Once the QNetworkCookieJar object is deleted, all cookies it held will be discarded as well. If you want to save the cookies, you should derive from this class and implement the saving to disk to your own storage format. (From QNetworkCookieJar documentation.)

    You can do this either by pushing to permanent storage on each QNetworkCookieJar::setCookiesFromUrl (safest but slowest) or only when the browser window is closed (faster overall but less safe as if you exit abnormally cookie jar won't be saved).

    Note that some cookies are not supposed to be persisted, you can use QNetworkCookie::isSessionCookie to determine this.

提交回复
热议问题