Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannot read second XML element
Qt 6.11 is out! See what's new in the release blog

Cannot read second XML element

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 752 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • fire_lizardF Offline
    fire_lizardF Offline
    fire_lizard
    wrote on last edited by
    #1

    The question is:

    I have the following XML file which I believe is valid XML:

    <?xml version="1.0" encoding="UTF-8"?>
    <Style>3</Style>
    <GameVariant>5</GameVariant>
    

    and have the following code to read it:

    QString settingsFile = settingsDir + "/QBoardSettings.xml";
        QFile file(settingsFile);
        file.open(QIODevice::ReadOnly | QIODevice::Text);
        QXmlStreamReader xmlStreamReader(&file);
        while (xmlStreamReader.readNextStartElement()) {
                QString s = xmlStreamReader.name().toString();
                qDebug(qPrintable(s));
        }
    

    But this code prints only "Style" instead of printing names for both elements. What I am doing wrong? Thanks in advance.

    Venkatesh VV 1 Reply Last reply
    0
    • fire_lizardF fire_lizard

      The question is:

      I have the following XML file which I believe is valid XML:

      <?xml version="1.0" encoding="UTF-8"?>
      <Style>3</Style>
      <GameVariant>5</GameVariant>
      

      and have the following code to read it:

      QString settingsFile = settingsDir + "/QBoardSettings.xml";
          QFile file(settingsFile);
          file.open(QIODevice::ReadOnly | QIODevice::Text);
          QXmlStreamReader xmlStreamReader(&file);
          while (xmlStreamReader.readNextStartElement()) {
                  QString s = xmlStreamReader.name().toString();
                  qDebug(qPrintable(s));
          }
      

      But this code prints only "Style" instead of printing names for both elements. What I am doing wrong? Thanks in advance.

      Venkatesh VV Offline
      Venkatesh VV Offline
      Venkatesh V
      wrote on last edited by
      #2

      Hi @fire_lizard

      Instead of using readNextStartElement() in While loop, use atEnd() method to parse the xml file till end.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved