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. QXmlStreamReader::attributes() not consistent ?
QtWS25 Last Chance

QXmlStreamReader::attributes() not consistent ?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 2.1k Views
  • 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.
  • G Offline
    G Offline
    grpace
    wrote on last edited by
    #1

    Greetings, all.

    I'm running into an issue using QXmlStreamReader::attributes(). It appears that it may not be recognizing element attributes consistently.

    I have assembled an image of the issue which you should be able to see here. At the top left of the image is a QTreeWidget I'm parsing the XML to. At the top right is the raw XML. Below that is the parsing code and Application Output window. The relevant parts are highlighted in yellow.

    What I'm finding odd is the section of code that parses the element attributes works in other sections of the XML (the code is a direct copy/paste), which makes me wonder if it's not something with the particular XML tags in question.

    Could someone look this over and suggest what may be causing the issue ?
    Thanks in advance !

    1 Reply Last reply
    1
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      The problem is in your algorithm. attributes() works only if you are at the start of an element. when you call readElementText() in line 441 you move your "cursor" beyond the start element so you can't read the attributes any more.

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      R 1 Reply Last reply
      5
      • G Offline
        G Offline
        grpace
        wrote on last edited by
        #3

        Thank you, @VRonin !
        That was it !
        I guess I didn't realize readElementText() moves the "cursor" the way it does.

        Thanks a bunch !!

        1 Reply Last reply
        1
        • VRoninV VRonin

          The problem is in your algorithm. attributes() works only if you are at the start of an element. when you call readElementText() in line 441 you move your "cursor" beyond the start element so you can't read the attributes any more.

          R Offline
          R Offline
          robson-estek
          wrote on last edited by
          #4

          @VRonin said in QXmlStreamReader::attributes() not consistent ?:

          The problem is in your algorithm. attributes() works only if you are at the start of an element. when you call readElementText() in line 441 you move your "cursor" beyond the start element so you can't read the attributes any more.

          I've spent a lot of hours trying to find a solution for this problem, your solution should the Qt documentation!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! there is nothing in the XMLStreamReader::attributes() or XMLStreamReader::readElementText() saying anything about this interaction!!!!!!

          kshegunovK 1 Reply Last reply
          0
          • R robson-estek

            @VRonin said in QXmlStreamReader::attributes() not consistent ?:

            The problem is in your algorithm. attributes() works only if you are at the start of an element. when you call readElementText() in line 441 you move your "cursor" beyond the start element so you can't read the attributes any more.

            I've spent a lot of hours trying to find a solution for this problem, your solution should the Qt documentation!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! there is nothing in the XMLStreamReader::attributes() or XMLStreamReader::readElementText() saying anything about this interaction!!!!!!

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @robson-estek said in QXmlStreamReader::attributes() not consistent ?:

            your solution should the Qt documentation!

            I would argue it is already in the documentation, you just need to read carefully.

            Here's for QXmlStreamReader::attributes():

            Returns the attributes of a StartElement.

            And for QXmlStreamReader::readElementText():

            Convenience function to be called in case a StartElement was read. Reads until the corresponding EndElement and returns all text in-between. In case of no error, the current token (see tokenType()) after having called this function is EndElement.

            So yes, you can't read the attributes for a StartElement token, after you've moved to the EndElement token.

            Read and abide by the Qt Code of Conduct

            R 1 Reply Last reply
            3
            • kshegunovK kshegunov

              @robson-estek said in QXmlStreamReader::attributes() not consistent ?:

              your solution should the Qt documentation!

              I would argue it is already in the documentation, you just need to read carefully.

              Here's for QXmlStreamReader::attributes():

              Returns the attributes of a StartElement.

              And for QXmlStreamReader::readElementText():

              Convenience function to be called in case a StartElement was read. Reads until the corresponding EndElement and returns all text in-between. In case of no error, the current token (see tokenType()) after having called this function is EndElement.

              So yes, you can't read the attributes for a StartElement token, after you've moved to the EndElement token.

              R Offline
              R Offline
              robson-estek
              wrote on last edited by
              #6

              @kshegunov true! I guess I was tired and didn't pay enough attention, anyway @VRonin 's explanation made everything more clear.

              1 Reply Last reply
              0

              • Login

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