开发者

In Qt QwebKit how can I delete all cookies when starting?

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


Pass an empty list to QNetworkCookieJar::setAllCookies()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜