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, readElementText method
Qt 6.11 is out! See what's new in the release blog

QXmlStreamReader, readElementText method

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 747 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.
  • A Offline
    A Offline
    Aymeric_Qt
    wrote on last edited by
    #1

    Hello everyone,
    This question might be more related to pure C++ than to Qt.

    While using QXmlStreamReader I've ran into a strange behavior.
    Here is the code I had:

    QXmlStreamReader reader;
    reader.addData(data);
    
    while(reader.readNextStartElement())
        {
            if (reader.name() == "api_url")
            {
                qDebug() << reader.readElementText();
                //m_apiUrl is a QString private member variable
                m_apiUrl = reader.readElementText();
                qDebug() << "m_apiUrl: " << m_apiUrl;
            }
        }
    

    In this case the m_apiUrl variable value was set to an empty string.
    But as soon as I've deleted the first qDebug statement m_apiUrl was set with a correct value.

    So I would like to know what happened and why.

    Thank you for reading.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Aymeric_Qt said in QXmlStreamReader, readElementText method:

      So I would like to know what happened and why.

      See the documentation - you read the element, so it's already read and the next call to readElementText() will not return anything.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • A Offline
        A Offline
        Aymeric_Qt
        wrote on last edited by
        #3

        @Christian-Ehrlicher I missed that when I've read the documentation. Thank you!

        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