Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.9.2
-
None
-
os: mac 10.12.6
qt: 5.9.2
-
0adf276e0b28e5937ab3c06ae889c03263352b3d
Description
QList<QNetworkCookie> cookies; QObject::connect(Browser->page()->profile()->cookieStore(), &QWebEngineCookieStore::cookieAdded, [this](const QNetworkCookie &cookie) { cookies.append(cookie); qDebug() << "Cookie Added -" << cookie.domain() << cookie.name() << endl; }); // First visit, the cookies was saved correctly (the server sent any cookies with domain - aa.bb.cc.com). Browser->load(QUrl("https://aa.bb.cc.com")); // Next time to re-visit it with the saved cookies Browser->page()->profile()->cookieStore()->deleteAllCookies(); for (auto cookie : cookies) { Browser->page()->profile()->cookieStore()->setCookie(cookie); or Browser->page()->profile()->cookieStore()->setCookie(cookie, QUrl("https://aa.bb.cc.com")); qDebug() << "[account] set>>" << cookie.domain() << cookie.name() << endl; } Browser->load(QUrl("https://aa.bb.cc.com")); // the cookie domain has been changed by QWebEngineCookieStore::setCookie, it will automatically add a leading dot to the domain
Result: // first visit Cookie Added - "aa.bb.cc.com" "uuid" // second visit [account] set>> "aa.bb.cc.com" "uuid" Cookie Added - ".aa.bb.cc.com" "uuid"