【问题标题】:QT 5.6 QWebEngine doesn't save cookiesQT 5.6 QWebEngine 不保存 cookie
【发布时间】:2022-02-10 21:53:57
【问题描述】:

我正在创建名为“webengine”的简单 QT 应用程序

pWebView = new QWebEngineView(this);
pWebView->load(QUrl("http://technoz.ru"));
pWebView->show();
// On application close
delete pWebView;

应用程序创建一个名为“webengine”的标准文件夹,用于存储和 cookie。域设置 24 小时的 cookie。但是在关闭并再次打开应用程序后,cookies 丢失了。在文件夹“webengine”中创建的 ?ookies 文件 - 空(我在 sqlbrowser 中检查它)。但是,如果您在第 30 到 40 秒停留,cookie 会被保存。

为什么 cookie 不立即保存,如何立即保存?


在测试过程中,QT(chromium) 会在 30 秒(常数)内通过浏览器自动存储 cookie,如果经过的时间更短,cookie 不会被保存。这次能改吗?我尝试使用标志 - --profiling-flush=5,但没有帮助。

鉴于关闭浏览器时浏览器必须保留存储(cookies),但它没有,是否是一个错误QT?


我认为我可以从源代码构建 QT,并在源代码中找到并更改此设置,但是,也许这个问题有其他解决方案...


谢谢大家,发现它的错误: https://bugreports.qt.io/browse/QTBUG-52121

【问题讨论】:

  • 感谢您的回答,但它适用于带有 WebKit 的 4.8 版。 QWebEngine 使用铬存储 fot cookie 管理。我尝试使用 QWebEngineCookiesStore 进行手动 cookie 管理,但 cookie 存储异步,大量 cookie 效果不佳。

标签: c++ qt cookies qt5


【解决方案1】:

您必须编辑 QWebEngineProfile 的 cookie 存储策略。如果您使用的是默认配置文件,请使用:

QWebEngineProfile::defaultProfile()->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies)

会话 cookie 和持久 cookie 都保存到磁盘并从磁盘恢复。您可以选择保存 cookie 和缓存数据的文件夹:

QWebEngineProfile* defaultProfile = QWebEngineProfile::defaultProfile();
defaultProfile->setCachePath("your folder");
defaultProfile->setPersistentStoragePath("your folder"); 

【讨论】:

  • 非常感谢。
猜你喜欢
  • 2023-04-09
  • 1970-01-01
  • 1970-01-01
  • 2012-01-19
  • 1970-01-01
  • 2021-11-03
  • 1970-01-01
  • 1970-01-01
  • 2015-05-01
相关资源
最近更新 更多