Results 1 to 12 of 12

Thread: QNetworkCookieJar

Threaded View

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

    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.

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.