How to make a custom cookie jar?
-
wrote on 23 Feb 2014, 00:06 last edited by
Hello there,
I have been working on my web browser, and I am wondering how I could make a cookie jar. I am not sure how I would go about this. Any suggestions?
-
This example subclasses QNetworkCookieJar: http://qt-project.org/doc/qt-5/qtwebkitexamples-webkitwidgets-browser-example.html
-
wrote on 8 Mar 2014, 21:06 last edited by
that exactly what Im looking for, thanks!
-
wrote on 8 Mar 2014, 21:14 last edited by
If I use QNetworkCookieJar, will I have to tell my webView to check if there is a cookie from the site its loading already in my cookie jar? If so how do I do this? Thanks!
-
I don't know, sorry; I've never done something like this before.
I imagine that the example shows you how to make QWebView interact with the custom cookie jar.
-
wrote on 9 Mar 2014, 00:52 last edited by
Ok so I have subclassed QNetworkCookieJar and made my custom cookie jar called NBcookieJar. I would like to be able to use NBcookieJar as an argument for one of my classes. I have several classes: mainView, browseTab, and NBcookieJar. mainView creates an instance of browseTab which contains a QWebView. I would like to also create an instance of NBcookieJar in mainView and use that instance as a parameter when creating the browseTab.
I tried to do this but I got this error:
error: missing default argument on parameter 'jar'I realize that I have not provided a default argument, but I have no idea what kind of argument I am supposed to provide.
here is my code:
browseTab.h:
@
public:
explicit browseTab(QWidget *parent = 0, QString url = "www.google.com", NBcookieJar jar);
@browseTab.cpp:
@browseTab::browseTab(QWidget *parent, QString url, NBcookieJar jar) :
QWidget(parent),@What is the default argument I should give for NBcookieJar jar?
Thanks!
-
Why do you pass your cookie jar by-value? You will end up with multiple copies of the cookie jar. When a cookie arrives, it will be stored in one jar, and the other copies won't get the cookie.
You should pass pointers or references to the cookie jar instead.
-
wrote on 9 Mar 2014, 01:34 last edited by
Yep just figured it out, changed the argument to a pointer. I declared the instance of NBcookieJar in mainView, then passed that to the argument. That way all the cookies are being stored in the instance in mainView and are accessible to all the browseTab's that are open. Works great! but now I need to figure out how to save the cookies to disk and manage them (I believe QNetworkCookieJar just saves them in memory until the application closes). Any ideas?
-
It's in the example