Results 1 to 12 of 12

Thread: QNetworkCookieJar

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QNetworkCookieJar

    Quote Originally Posted by ttimt View Post
    What's that
    A method?
    This usually refers to a function declared as part of a class's interface.

    Cheers,
    _

  2. #2
    Join Date
    Nov 2012
    Posts
    47
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: QNetworkCookieJar

    Quote Originally Posted by anda_skoa View Post
    A method?
    This usually refers to a function declared as part of a class's interface.

    Cheers,
    _
    The Save/Load



    I tried to check for cookie name before writing to file but this is outputting nothing?

    Qt Code:
    1. //Setup
    2. QList<QNetworkCookie> cookies = QNetworkCookieJar::allCookies();
    3. QFile cookiesfile("cookiefile");
    4. QTextStream in(&cookiesfile);
    5. QList<QString> savedcookies;
    6.  
    7. //Read
    8. if (!cookiesfile.open(QFile::ReadOnly | QFile::Text))
    9. {
    10. emit networkreplyError("Failed to open file for reading!");
    11. }
    12. while (!cookiesfile.atEnd())
    13. {
    14. savedcookies << in.readLine();
    15. }
    16. in.flush();
    17. cookiesfile.close();
    18.  
    19. //Append
    20. QTextStream out(&cookiesfile);
    21. if (cookiesfile.open(QFile::Append | QFile::Text))
    22. {
    23. emit networkreplyError("Failed to open file for reading");
    24. }
    25.  
    26. foreach (QNetworkCookie cookie, cookieList)
    27. {
    28. for (int i = savedcookies.size()-1; i >= 0; i--)
    29. {//will add check URL later
    30. if (!savedcookies.at(i).contains(cookie.name()))
    31. {
    32. //Name, Value, Path, Domain, Expire Date, URL
    33. out << "Name:" << cookie.name() << " spliter " << "Value:" << cookie.value() << " spliter " << "Path:" << cookie.path() << " spliter " << "Domain:" << cookie.domain() << " spliter " << "Expire Date:" << cookie.expirationDate().toString() << " spliter " << "URL:" << url.toString() << endl;
    34. out.flush();
    35. cookies += cookie;
    36. }
    37. }
    38. }
    39.  
    40. //Close and Return
    41. cookiesfile.close();
    42. return true;
    To copy to clipboard, switch view to plain text mode 
    Last edited by ttimt; 27th February 2014 at 11:43.

  3. #3
    Join Date
    Feb 2014
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QNetworkCookieJar

    Hello, everyone

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QNetworkCookieJar

    Quote Originally Posted by ttimt View Post
    The Save/Load
    Oh, I thought that would be self explanatory :-)
    A save method would write the cookies into a file and a load method would read them from a file.

    Quote Originally Posted by ttimt View Post
    I tried to check for cookie name before writing to file but this is outputting nothing?
    I am not quite sure what you are trying to do here and where in the class you are doing it.
    Trying to avoid duplicates in setCookiesForUrl()?

    That would be another thing that is easier in an explicit save method, because there you can just overwrite the file with the current jar content.

    Cheers,
    _

  5. #5
    Join Date
    Nov 2012
    Posts
    47
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: QNetworkCookieJar

    I mean what save/load is that, that get "called at the end/start" ?
    Maybe I misinterpreted this.
    You probably saying create functions that get called at the end/start, not some special qt save/load function that is not created by me


    I'm in NetworkJar class, subclass QNetworkCookieJar.
    That function is setCookiesforUrl, trying to check if cookies already exists before writing.
    Last edited by ttimt; 27th February 2014 at 13:08.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QNetworkCookieJar

    Quote Originally Posted by ttimt View Post
    I mean what save/load is that, that get "called at the end/start" ?
    Maybe I misinterpreted this.
    You probably saying create functions that get called at the end/start, not some special qt save/load function that is not created by me
    Exactly. I was suggeting to use explicit methods for saving and loading instead of making the setter and getter do it on every invocation.

    Cheers,
    _

  7. #7
    Join Date
    Nov 2012
    Posts
    47
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: QNetworkCookieJar

    Do I need to use setallcookies if I returned a Qlist<QNetworkCookie> in cookiesforurl ???
    I'm a newbie. Don't trust me

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QNetworkCookieJar

    I doubt it. setAllCookies() sounds more like the function you would call in a load method, i.e. to initially fill the cookie jar.

    Cheers,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    ttimt (2nd March 2014)

  10. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: QNetworkCookieJar

    The Qt browser demo implements cookie persistence. See cookiejar.h and cpp.

Similar Threads

  1. Replies: 2
    Last Post: 1st March 2012, 10:59
  2. QWebView and set QNetworkCookieJar
    By Talei in forum Newbie
    Replies: 0
    Last Post: 10th June 2010, 06:20
  3. Replies: 11
    Last Post: 12th July 2009, 16:01
  4. Replies: 1
    Last Post: 17th February 2009, 16:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.