title: Qt QNetworkAccessManager always return empty data and the status code is 0
body: <p>I met a strange problem and I have searched for several hours but cannot find solution.</p>
  
  <p>I am using Qt to write a Windows desktop application and I want to download a file from the Internet so I use <code>QNetworkAccessManager</code>. Following is my test code, which is in the MainWindow's constructor:</p>
  
  <pre><code>QNetworkRequest request;
  request.setUrl(QUrl("www.example.org"));
  QNetworkAccessManager *manager = new QNetworkAccessManager(this);
  if(manager-&gt;networkAccessible() == QNetworkAccessManager::Accessible){
      qDebug() &lt;&lt; "Network accessible";
  }
  else{
      qDebug() &lt;&lt; "Network is not accessible";
  }
  manager-&gt;get(request);
  connect(manager, manager-&gt;finished, this, connFinished);
  </code></pre>
  
  <p>And next is <code>connFinished</code> function:</p>
  
  <pre><code>void MainWindow::connFinished(QNetworkReply *r){
      int statusCode = r-&gt;attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
      qDebug() &lt;&lt; statusCode;
  }
  </code></pre>
  
  <p>After running the code, the output is:</p>
  
  <pre><code>Network accessible
  0
  </code></pre>
  
  <p>I'm sure that the <code>www.example.org</code> can be accessed in my machine and there is <strong>no redirection</strong>. The HTTP status code is 0 even my PC has disconnected from the Internet. The problem still happens in a new project so it's not only this project's problem.</p>
  
  <p><strong>My Qt version</strong>: Qt 5.5.1 (MSVC 2013, 32 bit)</p>
  
  <p><strong>Compiler</strong>: gcc version 5.1.0 (tdm-1)</p>
  
  <p>Is there anyone knows why this happened? Thanks!</p>
  
  <p>Project files and code:</p>
  
  <p>test.pro</p>
  
  <pre><code>QT       += core gui network
  
  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
  
  TARGET = test
  TEMPLATE = app
  
  
  SOURCES += main.cpp\
          mainwindow.cpp
  
  HEADERS  += mainwindow.h
  
  FORMS    += mainwindow.ui
  </code></pre>
  
  <p>mainwindow.h</p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  #include &lt;QUrl&gt;
  #include &lt;QNetworkRequest&gt;
  #include &lt;QNetworkReply&gt;
  #include &lt;QNetworkAccessManager&gt;
  
  namespace Ui {
  class MainWindow;
  }
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();
      void connFinished(QNetworkReply *r);
  
  private:
      Ui::MainWindow *ui;
  };
  
  #endif // MAINWINDOW_H
  </code></pre>
  
  <p>mainwindow.cpp</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  #include &lt;QDebug&gt;
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
      QNetworkRequest request;
      request.setUrl(QUrl("www.example.org"));
      QNetworkAccessManager *manager = new QNetworkAccessManager(this);
      if(manager-&gt;networkAccessible() == QNetworkAccessManager::Accessible){
          qDebug() &lt;&lt; "Network accessible";
      }
      else{
          qDebug() &lt;&lt; "Network is not accessible";
      }
      manager-&gt;get(request);
      connect(manager, manager-&gt;finished, this, connFinished);
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  void MainWindow::connFinished(QNetworkReply *r){
      int statusCode = r-&gt;attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
      qDebug() &lt;&lt; statusCode;
  }
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include "mainwindow.h"
  #include &lt;QApplication&gt;
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();
  
      return a.exec();
  }
  </code></pre>