[Qt-interest] QString doesn't print anything with qDebug
Elliot Smith
elliot.smith at intel.com
Wed Dec 1 14:17:38 CET 2010
On Wed, 2010-12-01 at 12:22 +0000, Anisha Kaul wrote:
>
> I wrote a small code to print the tag names, and no characters EXCEPT THE SPACES get shown up when I run it.
> The relevant (successfully compiled) code is presented here:
My guess is it's printing the whitespace characters inside each element,
before the next element start tag is encountered. If you did more
readNext() calls, you'd probably eventually see some non-whitespace,
non-text elements.
I think you want something like this if you want to see the (start) tag
names:
################################################################
#include <QtCore/QCoreApplication>
#include <QFile>
#include <QXmlStreamReader>
#include <QDebug>
int main(int argc, char *argv[])
{
QFile *objQFile = new QFile ("config.xml");
if (objQFile->open(QIODevice::ReadOnly) == false)
{
qDebug() << "\nError: Unable to open the XML file! Verify the file's
existence and permissions\n\n";
exit (1);
}
QXmlStreamReader objQXmlReader(objQFile);
while (!objQXmlReader.atEnd())
{
objQXmlReader.readNext();
if (objQXmlReader.isStartElement()) {
qDebug() << objQXmlReader.name().toString();
}
}
exit (0);
}
################################################################
You can do more testing of the type of element in the while() loop if
required, but the code above prints out just the start tags for each
element.
Elliot
--
Elliot Smith
Intel Open Source Technology Centre
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
More information about the Qt-interest-old
mailing list