gpt4 book ai didi

c++ - QT 5.6 QWebEngine 不保存 cookie

转载 作者:太空狗 更新时间:2023-10-29 21:37:33 30 4
gpt4 key购买 nike

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

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

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

为什么cookies没有立即保存,如何立即保存?


在测试过程中,发现 QT(chromium) 会在 30 秒(常数)内通过浏览器自动存储 cookie,如果耗时较少,则不会保存 cookie。这次有可能改变吗?我尝试使用标志 - --profiling-flush=5,但它没有帮助。

假设浏览器在关闭浏览器时必须保留存储(cookies),但没有,是否是QT的bug?


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


感谢大家,发现了bug: https://bugreports.qt.io/browse/QTBUG-52121

最佳答案

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

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

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

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

关于c++ - QT 5.6 QWebEngine 不保存 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37336396/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com