Ockonal Ockonal - 26 days ago 22
C++ Question

XML file from internet and Qt

I want to parse some XML-file in Qt, but that file is located at some server in web. When I used QML I was able to use

XMLHttpRequest
class which takes address of file in internet (what I do need).

I have only one idea: use network request and download that xml directly. The idea is maybe there is a special interface in XML parser in qt which takes xml-path from internet?

Answer

As I know, you should download it. QHttp provides easy way to download it to a temporary file.

QTemporaryFile temp_file;
QHttp http("example.com");
http.get("/your.xml",&temp_file);

New version (based on QNetworkAccessManager):

QNetworkAccessManager * manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(fileIsReady(QNetworkReply*)) );
manager->get(QNetworkRequest(QUrl("http://example.com/your.xml")));
...
void fileIsReady( QNetworkReply * reply)
{
  QTemporaryFile temp_file;
  temp_file.write(reply->readAll());
}