在 Qt QwebKit 中,如何在启动时删除所有 cookie?
我实现了cookie 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;
};
I implemented the cookies jar as shown in the web, and I can receive all the cookies values;
but how can I delete all cookies I don't understand? Here is my code where can I trigger the delete all cookies and how?
#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;
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将空列表传递给
QNetworkCookieJar::setAllCookies()
Pass an empty list to
QNetworkCookieJar::setAllCookies()