在 Qt QwebKit 中,如何在启动时删除所有 cookie?

发布于 2024-10-29 00:09:43 字数 2198 浏览 0 评论 0原文

我实现了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国粹 2024-11-05 00:09:43

将空列表传递给 QNetworkCookieJar::setAllCookies()

Pass an empty list to QNetworkCookieJar::setAllCookies()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文