Hello!
Objective: To load different pages of one site, with the ability to use previously issued cookie

The simplest application loads the page from localhost.

Qt Code:
  1. #include <QtCore>
  2. #include <QApplication>
  3. #include <QDebug>
  4. #include <QtNetwork>
  5.  
  6. class MyCookieJar : public QNetworkCookieJar
  7. {
  8. public:
  9. QList<QNetworkCookie> getAllCookies() { return allCookies(); }
  10. };
  11.  
  12.  
  13. class CookiesTest : public QObject
  14. {
  15. Q_OBJECT
  16. public:
  17. CookiesTest(QWidget* parent = 0);
  18.  
  19. private slots:
  20. void replyFinished(QNetworkReply*);
  21.  
  22. private:
  23. QNetworkAccessManager* manager;
  24. MyCookieJar *cookieJar;
  25. };
  26.  
  27. CookiesTest::CookiesTest(QWidget* parent)
  28. {
  29. manager = new QNetworkAccessManager;
  30. connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
  31.  
  32. cookieJar = new MyCookieJar;
  33. manager->setCookieJar(cookieJar);
  34.  
  35. manager->get(QNetworkRequest(QUrl("http://test1.ru/test/cookie.php")));
  36. manager->get(QNetworkRequest(QUrl("http://test1.ru/test/cookie.php")));
  37. }
  38.  
  39. void CookiesTest::replyFinished(QNetworkReply* reply)
  40. {
  41. qDebug() << reply->readAll();
  42. qDebug() << "getAllCookies: " << cookieJar->getAllCookies();
  43. }
  44.  
  45.  
  46. int main(int argc, char* argv[])
  47. {
  48. QApplication app(argc, argv);
  49. CookiesTest cookiesTest;
  50. return app.exec();
  51. }
  52.  
  53. #include "main.moc"
To copy to clipboard, switch view to plain text mode 
in the file .pro: QT += network

File cookie.php shows number of visits that page on the analysis of the cookie
Qt Code:
  1. <?php
  2. if (isset($_COOKIE['Mortal'])) $cnt = $_COOKIE['Mortal'] + 1;
  3. else $cnt = 1;
  4.  
  5. setcookie("Mortal",$cnt,0x6FFFFFFF);
  6. echo "NUM: [".@$_COOKIE['Mortal']."]";
  7. ?>
To copy to clipboard, switch view to plain text mode 
Output:
"NUM: []"
getAllCookies: (QNetworkCookie("Mortal=1; expires=Wed, 18-Jul-2029 05:49:51 GMT; domain=test1.ru; path=/test/") )
"NUM: []"
getAllCookies: (QNetworkCookie("Mortal=1; expires=Wed, 18-Jul-2029 05:49:51 GMT; domain=test1.ru; path=/test/") )
Although to be the second time in brackets the number 1 and the second getAllCookies: Mortal = 2

Tell me please, where was the mistake, what's wrong? Why cookies are not stored on the 2nd request