Qt WebKit和永久Cookie [英] Qt WebKit and Permanent Cookies

查看:318
本文介绍了Qt WebKit和永久Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主窗口,在它,我有一个单一的QWebView。
我想让某个网站(例如www.kdkdkkd.com)的cookies永久,所以每次用户关闭并重新打开浏览器,他不需要再次登录。

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 the browser he doesnt need to log in again.

感谢,

推荐答案

您需要设置自己的Cookie Jar。

You need to set your own "Cookie Jar".


  1. 使用 QNetworkAccessManager :: setCookieJar

  2. 扩展 QNetworkCookieJar - 默认情况下,浏览器关闭时不会保留Cookie:

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




一旦 QNetworkCookieJar 对象被
删除, be
也被丢弃。如果你想保存
的cookie,你应该从
这个类派生,并实现保存到
磁盘到你自己的存储格式。
(来自 QNetworkCookieJar 文档。)

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.)

您可以通过推送到每个 QNetworkCookieJar :: setCookiesFromUrl (最安全但最慢),或者只有当浏览器窗口关闭时(整体更快,但不安全,如果你退出异常cookie jar将不会被保存)。

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).

请注意,一些Cookie 不应被保留,您可以使用 QNetworkCookie :: isSessionCookie 来确定这一点。

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

这篇关于Qt WebKit和永久Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆