title: How do I save cookies with Qt?
body: <p>I am trying to save cookies that are produced by my app to disk location such as <code>C:\Users\Username\AppData\Local\MyCompany\MyApp</code>. I have implemented a webview and have pretty much finished coding my simple browser the final thing to do is save cookies. </p>
  
  <p>I am can qDebug() the cookies I get from the webapp and they show the cookies are formed correctly but I am a)unsure where to go from there and b) not 100% sure on how to make a subclass of the cookiejar class?</p>
  
  <p>Below I create my cookiejar object in my MainWindow constructor</p>
  
  <pre><code>view = new QWebView(this);
  jar = new QNetworkCookieJar;
  view-&gt;page()-&gt;networkAccessManager()-&gt;setCookieJar(jar);
  </code></pre>
  
  <p>And in my replyfinished slot I can see the cookie contained in the reply and I attempt to save it but nothing happens and I receive no run time errors. There isn't a great deal of stuff out there on this and have seen a few posts where the instruction was to make a subclass QNetworkCookieJar but have not made a subclass in Qt/C++ before.</p>
  
  <p>Is there a simple way to store cookies, I am not looking for anything fancy. The cookies just make sure some check boxes are ticked on the login page.</p>
  
  <pre><code>// SLOT that accepts the read data from the webpage
  void MainWindow::slotReplyFinished(QNetworkReply *reply){
  
      if(reply-&gt;isFinished()){
          QVariant variantCookies = reply-&gt;header(QNetworkRequest::SetCookieHeader);
          QList&lt;QNetworkCookie&gt; cookies = qvariant_cast&lt;QList&lt;QNetworkCookie&gt; &gt;(variantCookies);
          qDebug() &lt;&lt; "Cookies reply: " &lt;&lt; cookies;
          QNetworkCookie cookie; //Create a cookie
  
  
  
          jar = new QNetworkCookieJar;
          //view-&gt;page()-&gt;networkAccessManager()-&gt;setCookieJar(jar);
          jar-&gt;setCookiesFromUrl(cookies, reply-&gt;request().url());
          //qDebug() &lt;&lt; "Saved cookies: " &lt;&lt; jar-&gt;getAllCookies();
      }
  
      qDebug() &lt;&lt; "Network reply: " &lt;&lt; reply-&gt;errorString() &lt;&lt; reply-&gt;error() &lt;&lt; reply-&gt;request().url();
   }
  </code></pre>