How to make a custom cookie jar?
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
that exactly what Im looking for, thanks!
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.
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:
explicit browseTab(QWidget *parent = 0, QString url = "www.google.com", NBcookieJar jar);
@browseTab::browseTab(QWidget *parent, QString url, NBcookieJar jar) :
What is the default argument I should give for NBcookieJar jar?
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.
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