I checkout parser with socket. Documentation is lie or i do something wrong:
For example, if you read data from the network using QHttp, you would connect its readyRead() signal to a custom slot. In this slot, you read all available data with readAll() and pass it to the XML stream reader using addData(). Then you call your custom parsing function that reads the XML events from the reader.
When i run program i get:
QXmlStreamReader: addData() with device()
QXmlStreamReader: addData() with device()
To copy to clipboard, switch view to plain text mode
in console. Inside parser i set device as:
void MainWindow::onConnectionEstablished() {
qDebug() << "Connection established!";
if (!reader.read(socket)) {
...
bool XmlSpoListParser
::read(QIODevice *device
) { setDevice(device);
void MainWindow::onConnectionEstablished() {
qDebug() << "Connection established!";
if (!reader.read(socket)) {
...
bool XmlSpoListParser::read(QIODevice *device) {
setDevice(device);
To copy to clipboard, switch view to plain text mode
void MainWindow::readIncomingData()
{
qDebug() << "Get: " << socket->size() << " bytes.";
reader.addData(socket->readAll());
}
void MainWindow::readIncomingData()
{
qDebug() << "Get: " << socket->size() << " bytes.";
reader.addData(socket->readAll());
}
To copy to clipboard, switch view to plain text mode
If i remove setDevice() and write this code all work fine:
void MainWindow::readIncomingData() {
qDebug() << "Get: " << socket->size() << " bytes.";
reader.addData(socket->readAll());
reader.loop.quit();
}
...
class XmlSpoListParser : public QXmlStreamReader {
public:
XmlSpoListParser();
bool read();
...
void XmlSpoListParser::appendMoreData() {
loop.exec();
}
void MainWindow::readIncomingData() {
qDebug() << "Get: " << socket->size() << " bytes.";
reader.addData(socket->readAll());
reader.loop.quit();
}
...
class XmlSpoListParser : public QXmlStreamReader {
public:
XmlSpoListParser();
bool read(QIODevice *);
bool read();
QEventLoop loop;
...
void XmlSpoListParser::appendMoreData() {
loop.exec();
}
To copy to clipboard, switch view to plain text mode
bool XmlSpoListParser::onError() {
if (error() == QXmlStreamReader::PrematureEndOfDocumentError) {
appendMoreData();
return false;
} else {
qDebug() << errorString();
return true;
}
}
bool XmlSpoListParser::onError() {
if (error() == QXmlStreamReader::PrematureEndOfDocumentError) {
appendMoreData();
return false;
} else {
qDebug() << errorString();
return true;
}
}
To copy to clipboard, switch view to plain text mode
But code with QEventLoop looks ugly. How right?
Bookmarks