title: How can I download data from any link?
body: <p>I want to get string that appears on following link in my Qt program how can I get it ?</p>
  
  <p><a href="http://en.wikipedia.org/w/api.php?action=opensearch&amp;search=centaurus_constellation" rel="nofollow">http://en.wikipedia.org/w/api.php?action=opensearch&amp;search=centaurus_constellation</a></p>
  
  <p>I have coded following files to get string appearing on above page in m_DownloadedData, but it is storing empty string at the end of the program , can someone please help me get data from above link ?  </p>
  
  <p>.h file: </p>
  
  <pre><code>#ifndef SKYOBJDESCRIPTION_H
  #define SKYOBJDESCRIPTION_H
  
  #include &lt;QObject&gt;
  #include &lt;QByteArray&gt;
  #include &lt;QString&gt;
  #include &lt;QNetworkAccessManager&gt;
  #include &lt;QNetworkRequest&gt;
  #include &lt;QNetworkReply&gt;
  
  class SkyObjDescription : public QObject
  {
      Q_OBJECT
  public:
      explicit SkyObjDescription(const QString soName, const QString soType, QObject* parent = 0);
  
      virtual ~SkyObjDescription();
  
      QByteArray downloadedData() const;
  
  signals:
          void downloaded();
  
  private slots:
  
      void fileDownloaded(QNetworkReply* reply);
  
  private:
      QString soName,soType;
      QByteArray m_DownloadedData;
  
  };
  
  #endif // SKYOBJDESCRIPTION_H
  </code></pre>
  
  <p>and
  .cpp file</p>
  
  <pre><code>    #include &lt;QString&gt;
      #include &lt;QUrl&gt;
      #include &lt;QDebug&gt;
  
      #include "skyobjdescription.h"
  
  
      SkyObjDescription::SkyObjDescription(const QString so_Name, const QString so_Type, QObject* parent): soName(so_Name), soType(so_Type), QObject(parent)
      {
          QString wikiLink = "http://en.wikipedia.org/w/api.php?action=opensearch&amp;search="+ soName.replace(" ", "_").toLower() + "_" + soType.toLower() + "&amp;format=xml&amp;limit=1.xml";
  
   //       QUrl wikiUrl("http://en.wikipedia.org/w/api.php?action=opensearch&amp;search=hello_world&amp;format=xml&amp;limit=1.xml");
          m_DownloadedData = wikiUrl.toEncoded();
          qDebug() &lt;&lt; "wikiUrl.toEncoded(): " &lt;&lt; m_DownloadedData; 
          QNetworkRequest req(wikiUrl);
  
          QNetworkAccessManager* manager = new QNetworkAccessManager(this);
          connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(fileDownloaded(QNetworkReply*)));
          manager-&gt;get(req);
  
      }
  
      SkyObjDescription::~SkyObjDescription()
      {
  
      }
  
      void SkyObjDescription::fileDownloaded(QNetworkReply* reply)
      {
          m_DownloadedData = reply-&gt;readAll();
          qDebug() &lt;&lt; "received reply";
          qDebug() &lt;&lt; m_DownloadedData;
          reply-&gt;deleteLater();
          emit downloaded();
      }
  
      QByteArray SkyObjDescription::downloadedData() const
      {
          qDebug() &lt;&lt; m_DownloadedData;
          return m_DownloadedData;
      }
  </code></pre>
  
  <p>part of main.cpp</p>
  
  <pre><code>SkyObjDescription * skd = new SkyObjDescription(m_Name, "Constellation");
          QString data(skd-&gt;downloadedData());
          qDebug() &lt;&lt; data;
          delete skd;
  </code></pre>
  
  <p>If there is other way to get data from link please explain it.
  Thank you very much :)</p>