PDA

View Full Version : how QXmlStreamReader parse QString



SamSong
27th May 2009, 02:05
hi, all,
I have a string which is the xml structure. and I want to parse it by QXmlStreamReader,
but the QXmlStreamReader want the QIODevice as it's parametre, but I only have the string, so How do I convert the string to QIODevice ,is it use the
QBuffer buff(& myString.toUTF8),
or QTextStream textStream(&myString) and then textStream.device(),
both ways seems don't work , any help ,thanks very much!

codeslicer
27th May 2009, 02:17
QXmlStreamReader can accept a string:

http://doc.qtsoftware.com/4.5/qxmlstreamreader.html#QXmlStreamReader-4

~codeslicer

Muffin
6th November 2009, 14:56
I'm have the same problem here, i have tried using QBuffer,QByteArray and Qstring in different combinations with no succsess :(

below is the different ways that i have tried:


QSting xml; //with some xml structure

QByteArray bArray(xml);
QBuffer buffer;
QBuffer buffer(&bArray)
reader.setDevice(&buffer);

//or like this
buffer.setData(xml.toUtf8());

//then
buffer.open(QIODevice::ReadOnly)

//or this way
reader.addData(xml.toUtf8());

//what the heck! this then Grrr
QXmlStreamReader reader(xml);



after using "setDevice" or just "addData" etc i do the following:




int ret = reader.readNext();
while(!reader.atEnd())
{
if(reader.isStartElement())
{
if(reader.name() == "Application")
ReadApplicationElement();
else
reader.raiseError(QObject::tr("Error"));
}
else
reader.readNext();
}


What am i missing?? it's not the XML because i have tried with QFile and it works that way...

/Robert