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. Documentation confusion QXmlStreamReader::readNextStartElement
Forum Updated to NodeBB v4.3 + New Features

Documentation confusion QXmlStreamReader::readNextStartElement

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.6k 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.
  • L Offline
    L Offline
    lloydqt
    wrote on last edited by
    #1

    Hi,

    I am using "QXmlStreamReader::readNextStartElement" to parse an exm stream. The data is read from a network socket, I am using the following method.

    @mysocket mysock;
    QXmlStreamReader xmlreader;
    char buff[1024];
    int outlen=0;
    int err;
    while(mysock.ReadData(buff,1024,outlen)&&outlen!=0)
    {
    QByteArray byteArray(buff,outlen);
    xmlreader.addData(byteArray);
    while(1)
    {
    if(!xmlreader.readNextStartElement())
    {
    err=xmlreader.error();
    switch(err)
    {
    case QXmlStreamReader::NoError:
    break;
    case QXmlStreamReader::PrematureEndOfDocumentError:
    //some code to break the infinite while loop
    break;
    }
    }

    }
    }
    @

    In the code at line 8 & 9, if the "bytearray" is not fully parsed, whether the existing unparsed data will be lost? If so is there any alternative?

    And "readNextStartElement()" some times returns false, but when I check the error status using "error()" call, it returns "NoError"! Why this is happening?

    Thanks,
    Lloyd

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mkuettler
      wrote on last edited by
      #2

      Hello.

      I don't understand why any data should be partially parsed in line 8 or 9. Neither of these lines does any parsing as far as I can tell.

      The documentation of QXmlStreamReader::readNextStartElement states:

      bq. Returns true when a start element was reached. When the end element was reached, or when an error occurred, false is returned.

      So I guess when you see a false return value and now Error you just read the end element.

      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