QXmlStreamReader xml("This is some text. "); while (!xml.atEnd()) { xml.readNext(); if (xml.isCharacters()) { qDebug() << "Column number:" << xml.columnNumber() << " Text:" << xml.text(); } }
QFile file("data.xml"); if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QXmlStreamReader xml(&file); while (!xml.atEnd()) { xml.readNext(); qDebug() << "Column number:" << xml.columnNumber(); } file.close(); }This code reads an XML file using a QFile object and iterates through the tokens in the stream, outputting the column number of each token. In this example, the output would be the column number of every token in the XML document. Package/library: This code uses the QXmlStreamReader class from the Qt library, which is part of the Qt Core module.