Why is there no copying at QNetworCookieJar?
Page |
1 |
Hi,
I think the title says everything
there is the “Q_DISABLE_COPY(QNetworkCookieJar)” thing in the sourcecode and I and a friend which is a much better programmer than me were not able to find a reason for that.
My program would be much better if I could use the copy constructor.
Hope somebody can tell me.
25 replies
No it cannot. There is no explicitly defined copy constructor or assignment operator so it will try to use a default member-wise one created by the compiler which will fail when it tries to recurse to the base class’ (QObject’s) copy constructor or assignment operator.
Nothing derived from QObject can be copied because QObject marks its copy constructor and assignment operator as private.
You could subclass QNetworkObjectJar, and implement a clone function like this:
- MyNetworkCookieJar* MyNetworkCookieJar::getClone() const {
- MyNetworkCookieJar *newJar = new MyNetworkCookieJar;
- newJar->setAllCookies( allCookies() );
- return newJar
- }
But watch out: you must delete the returned pointer yourself. There is NO way of treating QObject derived classes as value types!
Class QNetworkCookie contains the URI the cookie is bound to. According to the API docs the methods allCookies() and setAllCookies() can be used to implement a permanent cookie storage. So I think the returned list of cookies contains all the necessary information. If not, I’d definitely call this a bug :-)
Hi,
I realized that my problem description was insufficient and the problem has not been solved yet.
I want to do something like this:
- {
- _CookieJar->setAllCookies(Cookies);
- }
- {
- return _CookieJar->allCookies();
- }
But since the functions “setAllCookies” and “allCookies” are protected I am unable to do so. What is the proper way to do what I want to do?
Hi,
I realized that my problem description was insufficient and the problem has not been solved yet.
I want to do something like this:
{ _CookieJar->setAllCookies(Cookies); } { return _CookieJar->allCookies(); }But since the functions “setAllCookies” and “allCookies” are protected I am unable to do so. What is the proper way to do what I want to do?
If all you want to do is access those methods from an outside class, then just make a trivial subclass of QNetworkCookieJar and make those two method public. You can then access them from your external class. If what you want to do really belongs to the cookie jar itself, perhaps implementing your functionality in that subclass itself would be a better choice. It may help to keep encapsulation.
You must log in to post a reply. Not a member yet? Register here!





