how QXmlStreamReader parse QString
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!
Re: how QXmlStreamReader parse QString
Re: how QXmlStreamReader parse QString
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:
Code:
QSting xml; //with some xml structure
reader.setDevice(&buffer);
//or like this
buffer.setData(xml.toUtf8());
//then
//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:
Code:
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