我实现了网络中显示的cookies jar,我可以收到所有的cookie值;
但是如何删除我不理解的所有cookie?这是我的代码,我可以在哪里触发删除所有cookie以及如何?
#include <QNetworkCookieJar>
class QNetworkCookieJarEx : public QNetworkCookieJar
{
public:
QNetworkCookieJarEx()
: mEnabled(true){ }
bool enabled() const
{
return mEnabled;
}
void setEnabled(bool enabled)
{
if(mEnabled != enabled)
{
mEnabled = enabled;
// Possibly clear cookies, if we could get access to the parent class container. However, currently it is private.
// so how can i delete all the cookies ?
}
}
QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const
{
if(mEnabled )
return QNetworkCookieJar::cookiesForUrl(url);
else
return QList<QNetworkCookie>();
}
bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url)
{
if(mEnabled )
{
QUrl u = url;
// here i can see the cookies values
QList<QNetworkCookie> cookies = allCookies();
foreach(QNetworkCookie cookie, cookieList) {
QString cookieName(cookie.name());
QString cookieValue(cookie.value());
QString cookiePath(cookie.path());
//simple logger
UT::getInstance()->MyLogToFile("cookieName:"+cookieName+
" cookieValue:"+cookieValue+
" cookiePath:"+cookiePath);
cookies += cookie;
}
return QNetworkCookieJar::setCookiesFromUrl(cookieList, url);
}
else
return false;
}
QList<QNetworkCookie> allCookies() const
{
if(mEnabled )
return QNetworkCookieJar::allCookies();
else
return QList<QNetworkCookie>();
}
void setAllCookies(const QList<QNetworkCookie>& cookieList)
{
if(mEnabled )
return QNetworkCookieJar::setAllCookies(cookieList);
}
protected:
bool mEnabled;
};
答案 0 :(得分:2)
将空列表发送到QNetworkCookieJar::setAllCookies()