I want to read an xml file as follow:
QFile myFile("xmlfile");
and then continue with parsing the xml starting from :
QXmlStreamReader xmlData(myFile);
.. the error I get is:
no matching function for call to 'QXmlStreamReader::QXmlStreamReader(QFile&)'
so what is the problem and how to solve it ?
question update: Based on the selected answer below, the code is now working without a syntax error .
however, I can not read my xml. when parsing the xml, I use the following to read xml elements:
QXmlStreamReader::TokenType token = xmlElements.readNext();
then this code for checking the startElements:
while(!xmlElements.atEnd() && !xmlElements.hasError()){ // the breakpoint is here
do ...
}
so, at this breakpoint, I notice in my debuger that token value is QXmlStreamReader::Invalid(1)
so, what is going on .. is my QStreamReader does not read the file as xml, or it read it but there is an error with the xml itself ?
I found the problem and everything is now working properly
here is the mistake: by previously using the following code:
the file is first created in the first line, the second line of code just pass the file as it not its xml content (since it is not been opened yet), therefore the QXmlStreamReader::errorString returns Premature end of document ..
the solution is very simple: open the "myFile" file before passing it to the QXmlStreamReader using the following code:
The device is now open for reading by QXmlStreamReader. and the final code is: