我正在尝试删除Cookie,但出现错误:error C2440: 'initializing' : cannot convert from 'const QNetworkCookie' to 'QNetworkCookie &'
我很困惑为什么编译器会抱怨const QNetworkCookie
(我假设它正在抱怨我的foreach()
)。
void PersistentCookieJar::deleteCookie(const QString cookieName) {
QList<QNetworkCookie> cookies = allCookies();
foreach(QNetworkCookie &cookie, allCookies()) {
if (cookie.name() == cookieName) {
cookie.setValue(""); // delete the cookie
break;
}
}
}
最佳答案
void PersistentCookieJar::deleteCookie(const QString cookieName) {
QList<QNetworkCookie> cookies = allCookies();
foreach(QNetworkCookie &cookie, cookies) {
if (cookie.name() == cookieName) {
cookie.setValue(""); // delete the cookie
break;
}
}
setAllCookies(cookies);
}