Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QNetworkCookieJar - Retrieving individual data from cookie
Forum Updated to NodeBB v4.3 + New Features

QNetworkCookieJar - Retrieving individual data from cookie

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maximus
    wrote on last edited by
    #1

    I have set up a standard QNetworkCookieJar to be used with multiple QWebView I use in my application.

    I need to retrieve some cookie data in order to create a custom c++ object
    However the function allCookie() is protected and I can't seem to get them.

    Anyone did this before?

    Here is my code trying to retrieve the cookies :
    @ QNetworkAccessManager nam = qApp->property("NetworkManager").value<QNetworkAccessManager>();
    QNetworkCookieJar *jar = nam->cookieJar();

    QList<QNetworkCookie> cookiesLst = jar->allCookies();
     for (int i = cookiesLst.count() - 1; i >= 0; --i) {
            qDebug() << "found cookie here";
     }@
    

    Thanks

    C:\Dropbox\PowerVelo2\gui\mainwindow.cpp:47: 'QNetworkCookieJar::allCookies' : cannot access protected member declared in class 'QNetworkCookieJar'


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      You can use "QNetworkCookieJar::cookiesForUrl":http://qt-project.org/doc/qt-5/qnetworkcookiejar.html#cookiesForUrl

      Or you can derive your class from QNetworkCookieJar and use allCookies() in that class as it is "suggested":http://qt-project.org/doc/qt-5/qnetworkcookiejar.html#allCookies in the doc.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        You can't access protect functions unless you are deriving from that class. From a quick look at QNetworkCookieJar, you'll have to use cookiesForUrl

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maximus
          wrote on last edited by
          #4

          Thanks for the guidance guys.
          cookiesForUrl is perfect for my needs, I don't need to persist the cookie for now.

          I'm using codeIgniter to set the cookie on the server side :
          http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

          I retrieve the cookie this way:
          @ QList<QNetworkCookie> cookiesLst = jar->cookiesForUrl(QUrl(Environnement::getURLEnvironnement()));

          foreach (QNetworkCookie cookie, cookiesLst) {
              qDebug() << cookie.name();
              qDebug() << cookie;
          }@
          

          log :
          @"ci_session"
          QNetworkCookie("ci_session=a:4:{s:10:"session_id";s:32:"ee434b8cba49682794ec50eeee959917";s:10:"ip_address";s:3:"::1";s:10:"user_agent";s:101:"Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/538.1+(KHTML,+like+Gecko)+MaximumTrainer+Safari/538.1";s:13:"last_activity";i:1405003057;}0aab4290e254a90ca848c80362216400; expires=Sat, 09-Jul-2016 14:37:50 GMT; domain=localhost; path=/")
          "localhost" @

          I'll have to find how to retrieve custom session data, so far it only return me the basic codeIgniter cookie but not the data I added. if it's too complex i'll just make a request to a webservice instead at the cost of one more DB requets.
          Thanks for the help guys


          Free Indoor Cycling Software - https://maximumtrainer.com

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved