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. How to add xml?

How to add xml?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 1.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.
  • Z Offline
    Z Offline
    zicx
    wrote on last edited by
    #1

    I am trying to build a simple xml reader using qt's stream reader. But I am running into trouble when I try to use xml

    I get

    C:\CPP\XmlTest\XmlTest\xmlreader.cpp:17: error: C2065: 'xml': undeclared identifier
    

    below is the .cpp

    #include "xmlreader.h"
    
    #include <qxmlstream.h>
    #include <qfile.h>
    
    
    XmlReader::XmlReader( const QString filename ) {
    
        this->filename_ = filename;
    
    }
    
    void XmlReader::Read() {
    
        QFile xmlfile(this->filename_);
        xmlfile.open( QIODevice::ReadOnly );
        xml.setDevice( &xmlfile );    // ERROR HERE
    
    
    } 
    

    I added this to the application's .pro

    QT += xml
    

    What else do I need to do to use xml. Is there another library I need to include?

    jsulmJ 1 Reply Last reply
    0
    • Z zicx

      I am trying to build a simple xml reader using qt's stream reader. But I am running into trouble when I try to use xml

      I get

      C:\CPP\XmlTest\XmlTest\xmlreader.cpp:17: error: C2065: 'xml': undeclared identifier
      

      below is the .cpp

      #include "xmlreader.h"
      
      #include <qxmlstream.h>
      #include <qfile.h>
      
      
      XmlReader::XmlReader( const QString filename ) {
      
          this->filename_ = filename;
      
      }
      
      void XmlReader::Read() {
      
          QFile xmlfile(this->filename_);
          xmlfile.open( QIODevice::ReadOnly );
          xml.setDevice( &xmlfile );    // ERROR HERE
      
      
      } 
      

      I added this to the application's .pro

      QT += xml
      

      What else do I need to do to use xml. Is there another library I need to include?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @zicx What is xml?

      void XmlReader::Read() {
      
          QFile xmlfile(this->filename_);
          xmlfile.open( QIODevice::ReadOnly );
          xml.setDevice( &xmlfile );    // What is xml?
      

      So, where and how did you declare it?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zicx
        wrote on last edited by
        #3

        Oh, I assumed that this is related to the +xml. some sort of way to include a special library. The example I looked at didn't declare it but it seems to be an instance of QXmlStreamReader.
        Thanks for the hint

        1 Reply Last reply
        0
        • K Offline
          K Offline
          karti gesar
          wrote on last edited by
          #4

          you can also use Qtextstream to read

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

            As a side note, QXmlStreamReader is part of the core module, no need to include QT += xml in the pro file

            "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

            1 Reply Last reply
            1

            • Login

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