QtWebEngine,如何在C++/Qt6.2.4中保存Cookie?

QtWebEngine, How to Save Cookies in C++/Qt6.2.4?

由于我将我的应用程序的 Qt5 更改为 Qt6,

什么对 Qt5 有效(为了保存 cookie,我关注了这个线程 QT 5.6 QWebEngine doesn't save cookies),

现在不工作:

    QWebEngineProfile::defaultProfile()->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
    QWebEngineProfile* defaultProfile = QWebEngineProfile::defaultProfile();

    defaultProfile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
    defaultProfile->setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
    QHttpPart* header = new QHttpPart;
    header->setRawHeader("X-Frame-Options", "ALLOWALL");

    defaultProfile->setCachePath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
    defaultProfile->setPersistentStoragePath(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation));

我需要保存 Cookie。

解决方案是:

    QWebEngineProfile *profile = new QWebEngineProfile(QString::fromLatin1("MyApplication.%1").arg(qWebEngineChromiumVersion()));  // unique profile store per qtwbengine version
    QWebEnginePage *page = new QWebEnginePage(profile); // page using profile
    QWebEngineView *view = new QWebEngineView();

    view->setPage(page);
    view->setUrl(AccueilUrl);
    view->setZoomFactor(1.2);

    setCentralWidget(view);