QT 5.6 QWebEngine不保存cookie

Але*_*ков 5 c++ cookies qt qt5

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

\n
pWebView = new QWebEngineView(this);\npWebView->load(QUrl("http://technoz.ru"));\npWebView->show();\n// On application close\ndelete pWebView;\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

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

\n
\n

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

\n

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

\n
\n

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

\n
\n

感谢大家,发现了错误:\n https://bugreports.qt.io/browse/QTBUG-52121

\n

moh*_*uje 3

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

QWebEngineProfile::defaultProfile()->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies)
Run Code Online (Sandbox Code Playgroud)

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

QWebEngineProfile* defaultProfile = QWebEngineProfile::defaultProfile();
defaultProfile->setCachePath("your folder");
defaultProfile->setPersistentStoragePath("your folder"); 
Run Code Online (Sandbox Code Playgroud)