Home > database >  QtWebEngine, How to Save Cookies in C /Qt6.2.4?
QtWebEngine, How to Save Cookies in C /Qt6.2.4?

Time:04-01

Since I change Qt5 to Qt6 for my app,

What worked for Qt5 (to save the cookies, I followed this thread QT 5.6 QWebEngine doesn't save cookies),

Doesn't work now :

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

I need to save Cookies.

CodePudding user response:

The Solution is :

    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);
  • Related