PDA

View Full Version : work with web generated xml



emental86
29th January 2009, 11:08
Hello,

I need to work with web generated xml document. If I work with local disk file, everithing's fine:


...
QFile file(url);
if(!file.open(QFile::ReadOnly | QFile::Text)) {
cout << "chyba!";
return;
}else{
cout << "soubor otevren...";
read(&file);
}
file.close();
...

You see, I send to method read pointer to file (QIODevice). I want to do something like this:


...
QUrl address = QUrl(url);

if(!address.open(QFile::ReadOnly | QFile::Text)) {
cout << "chyba!";
return;
}else{
cout << "soubor otevren...";
read(&address);
}
...

Of course I know, it's wrong. I found only QDesktopServices::openUrl ( const QUrl & url ) but it opens URL in web browser and I don't want this! I need to work with generated xml file.

It crossed my mind that I can save generated document to disk and then can I work with that like I want to. But I think it's soo complicated.

Thx for any answer...

emental86
11th February 2009, 13:51
Hello,

can anyone help me, with my problem? I have this code:



#include <iostream>
#include <QApplication>
#include <QIODevice>
#include <QFile>
#include <QTextStream>
#include <QUrl>
#include <QtNetwork>
#include <QHttp>
#include <QObject>

int main(int argc, char *argv[]){
QCoreApplication app(argc, argv);
QTextStream out(stdout);
QHttp *http = new QHttp();
QFile *file = new QFile("index.html");
file->open(QIODevice::WriteOnly);
http->setHost("www.trolltech.com");
out << http->errorString() << endl;
http->get(QUrl::toPercentEncoding("/index.html"), file);
out << http->errorString() << endl;
file->close();
return 0;
}


And the result is:

Unknown error
Unknown error

I tried many different versions of code, but the result is still that :( Know anybody what can by wrong?

Thx for all answers...