View Full Version : Downloading XML file

24th August 2014, 11:41
i want to get a XML file from online source,
how can i download it and store the data in QTemporaryFile or pass it directly to QXmlStreamReader

i tried a lot but i dont know what is the problem exactly

int main(int argc, char *argv[])
QCoreApplication a(argc, argv);
QNetworkAccessManager *manager = new QNetworkAccessManager;
QNetworkRequest request(QUrl("http://api.openweathermap.org/data/2.5/weather?q=skikda&mode=xml"));
QNetworkReply* reply = manager->get( request) ;
QXmlStreamReader reader( reply );

return a.exec();

24th August 2014, 14:18
QNetworkAccessManager works asynchronous, the get() call returns immediately and the actual transfer happens over time.

QNetworkReply is a QIODevice so it will signal incoming data via its readyRead() signal.
You can also wait for it to finish() and then read all data in one go.

QXmlStreamReader supports both partial data and full documents.


24th August 2014, 23:22
But none of this will happen if the app's event loop isn't running. So putting that code into main() before the QCoreApplication::exec() call will have no effect at all since there is no event loop yet to handle signals.