Unsolved Read data of a website
-
@Linz Hi, I don't know about the error (I personally would investigate that).
To parse XML you can use https://doc.qt.io/qt-5/qxmlstreamreader.html -
I fixed the error, something with my proxy was off ^^
Do you have an idea how I can convert the QByteArray buffer to a char? Would It make way more easy to access the values I need.
-
Hi,
No need to convert anything.
You can access the internal data using the QByteArray::data function.
-
@Linz said in Read data of a website:
Do you have an idea how I can convert the QByteArray buffer to a char? Would It make way more easy to access the values I need.
Don't do this.
@artwaw said in Read data of a website:
To parse XML you can use https://doc.qt.io/qt-5/qxmlstreamreader.html
Do this!
-
I somehow missed the XML part.
My fellows are correct, use QXmlStreamReader.
-
Sorry for bothering you: I read the documentation for QXmlStreamReader, but I still have no clue how to filter the data. Maybe I am still missing the basics too much to understand what I need...
If I refer to the picture I want to save the first value 49.986, the second value 132.3 and the third value 0 in an array(s) of type double (to plot it later on).
But which function could do this for me?
I tried something like:
void QXmlStreamReader::addData(const QByteArray &buffer);but it doesn't work. I could filter it easily if it would have been an array of char :/
-
higher level:
curl
wget -
@Linz
You just want to parse input XML. I don't think you'll particularly be needingQXmlStreamReader::addData()
. You're just wanting to read elements and access values.There is a Qt example at https://doc.qt.io/qt-5/qtxml-streambookmarks-example.html. But for you you're only interested in the
XbelReader::readXBEL()
part. It should get you started on how to read through an XML document. -
const QByteArray replyData = reply->readAll(); QXmlStreamReader xmlreader(replyData); bool rStarted = false; while (!xmlreader.atEnd() && !xmlreader.hasError()) { switch(xmlreader.readNext()){ case QXmlStreamReader::StartElement: if(xmlreader.name()==QLatin1String("r")) rStarted = true; else if(rStarted && xmlreader.name()==QLatin1String("f")) qDebug() << "f" << xmlreader.readElementText(); else if(rStarted && xmlreader.name()==QLatin1String("z")) qDebug() << "z" << xmlreader.readElementText(); else if(rStarted && xmlreader.name()==QLatin1String("p")) qDebug() << "p" << xmlreader.readElementText(); else if(rStarted && xmlreader.name()==QLatin1String("dt")) qDebug() << "dt" << xmlreader.readElementText(); break; case QXmlStreamReader::EndElement: if(xmlreader.name()==QLatin1String("r")) rStarted = false; break; default: break; } }
-
@VRonin Thanks a lot! Where do you define readElementText() since I get the Error:
Error: use of undeclared identifier 'readElementText'I tried to define it as QString readElementText() in the header, but it doesn't seem to work.
-
Sorry forgot to add
xmlreader.
amended now