Cookies not working



  • Hello, I am working with a QGraphicsWebView and I've created a class for persistent cookies managment. But it don't work. Here's code.
    @class PersistentCookieJar : public QNetworkCookieJar {
    public:
    PersistentCookieJar(QObject *parent) : QNetworkCookieJar(parent) { load(); }
    ~PersistentCookieJar() { save(); }

    public:
    void save()
    {
    QList<QNetworkCookie> list = allCookies();
    QByteArray data;
    foreach (QNetworkCookie cookie, list) {
    if (!cookie.isSessionCookie()) {
    data.append(cookie.toRawForm());
    data.append("\n");
    }
    }
    QSettings settings;
    settings.setValue("Cookies",data);
    }

    void load()
    {
        QSettings settings;
        QByteArray data = settings.value("Cookies").toByteArray();
        setAllCookies(QNetworkCookie::parseCookies(data));
    }
    

    };@

    I've implemented it in this way.
    @m_cookiejar = new PersistentCookieJar(this)
    page()->networkAccessManager()->setCookieJar(m_cookiejar);@

    Can someone help?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.