title: How to get text from website in Qt (QNetworkAccessManager not working)?
body: <p>I am trying to get text from a website using the <code>QNetworkAccessManager</code> class, but it's not working. <a href="http://doc.qt.io/qt-5/qnetworkaccessmanager.html#details" rel="nofollow noreferrer">When the replyFinished slot above is called, the parameter it takes is the QNetworkReply object containing the downloaded data as well as meta-data (headers, etc.)</a>. When the slot gets called, I append the gotten text to a QString and print it out, but it prints an empty string. Here is my code:</p>
  
  <pre><code>//.pro file
  TEMPLATE = app
  QT += qml quick
  QT += network
  CONFIG += c++11
  
  
  //xmlparser.h
  #ifndef XMLPARSER_H
  #define XMLPARSER_H
  
  #include &lt;QObject&gt;
  #include &lt;QNetworkAccessManager&gt;
  
  class XMLParser : public QNetworkAccessManager
  {
      Q_OBJECT
  public:
      ~XMLParser()=default;
      static XMLParser &amp;Instance();
      Q_INVOKABLE void readXML();
  
  signals:
      finished(QNetworkReply* reply);
  
  public slots:
      void replyFinished(QNetworkReply* reply);
  
  private:
      XMLParser()=default;
      XMLParser(XMLParser const&amp;)=delete;
      void operator = (XMLParser const&amp;)=delete;
  
      QByteArray m_text;
  };
  
  #endif // XMLPARSER_H
  
  
  //xmlparser.cpp
  #include &lt;QUrl&gt;
  #include &lt;QDebug&gt;
  #include &lt;QNetworkAccessManager&gt;
  #include &lt;QNetworkRequest&gt;
  #include &lt;QNetworkReply&gt;
  #include &lt;QEventLoop&gt;
  #include "xmlparser.h"
  
  XMLParser &amp;XMLParser::Instance()
  {
      static XMLParser instance;
      return instance;
  }
  void XMLParser::readXML()
  {
      QNetworkAccessManager *manager = new QNetworkAccessManager(this);
      connect(manager, SIGNAL(finished(QNetworkReply*)),
              this, SLOT(replyFinished(QNetworkReply*)));
      manager-&gt;get(QNetworkRequest(QUrl("http://qt-project.org")));
  }
  void XMLParser::replyFinished(QNetworkReply *reply)
  {
      QString text;
      text.append(reply-&gt;readAll());
      qDebug () &lt;&lt; "Text: " &lt;&lt; text; //Prints out emtpy string?
  }
  </code></pre>