I have this code like this:
bool XmlSpoListParser::read()
{
while (!atEnd()) {
readNext();
if (isStartElement()) {
readSomething1();
break;
} else {
raiseError
(QObject::tr("The file is not an Tag version 1.0 file."));
break;
}
}
if (hasError() && onError()) {
break;
}
}
return !error();
}
bool XmlSpoListParser::onError()
{
if (error() == QXmlStreamReader::PrematureEndOfDocumentError) {
appendMoreData();
return false;
} else {
qDebug() << errorString();
return true;
}
}
void XmlSpoListParser::appendMoreData()
{
//???
}
void XmlSpoListParser::readSomething1()
{
while (!(isEndElement
() && name
() == QLatin1String("Tag2")) && !atEnd
()) { readNext();
if (isStartElement()) {
readSomething2();
} else {
skipSubTree();
}
}
if (hasError() && onError()) {
break;
}
}
}
void XmlSpoListParser::readSomething2()
{
while (!(isEndElement
() && name
() == QLatin1String("Tag3")) && !atEnd
()) { readNext();
if (isStartElement()) {
readSomething3();
} else {
skipSubTree();
}
}
if (hasError() && onError()) {
break;
}
}
}
bool XmlSpoListParser::read()
{
while (!atEnd()) {
readNext();
if (isStartElement()) {
if (name() == QLatin1String("Tag") && attributes().value(QLatin1String("version")) == QLatin1String("1.0")) {
readSomething1();
break;
} else {
raiseError(QObject::tr("The file is not an Tag version 1.0 file."));
break;
}
}
if (hasError() && onError()) {
break;
}
}
return !error();
}
bool XmlSpoListParser::onError()
{
if (error() == QXmlStreamReader::PrematureEndOfDocumentError) {
appendMoreData();
return false;
} else {
qDebug() << errorString();
return true;
}
}
void XmlSpoListParser::appendMoreData()
{
//???
}
void XmlSpoListParser::readSomething1()
{
while (!(isEndElement() && name() == QLatin1String("Tag2")) && !atEnd()) {
readNext();
if (isStartElement()) {
if (name() == QLatin1String("Tag3")) {
readSomething2();
} else {
skipSubTree();
}
}
if (hasError() && onError()) {
break;
}
}
}
void XmlSpoListParser::readSomething2()
{
while (!(isEndElement() && name() == QLatin1String("Tag3")) && !atEnd()) {
readNext();
if (isStartElement()) {
if (name() == QLatin1String("Tag4")) {
readSomething3();
} else {
skipSubTree();
}
}
if (hasError() && onError()) {
break;
}
}
}
To copy to clipboard, switch view to plain text mode
How i can wait data from socket when error PrematureEndOfDocumentError occured from readSomething2() method (for example)? I wan't call addData() to parser and return back to method readSomething1() after new data arrived. What i must do, create additional QEventLoop in method appendMoreData, or use infinite while(1) with QApplication::processEvents() or what?
Bookmarks