How to make a custom cookie jar?
-
This example subclasses QNetworkCookieJar: http://qt-project.org/doc/qt-5/qtwebkitexamples-webkitwidgets-browser-example.html
-
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:
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.
-
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