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. Question regarding Tinyxml2 in a Qt app.
Forum Update on Monday, May 27th 2025

Question regarding Tinyxml2 in a Qt app.

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

    HI there.

    Hope you all doing great today.

    I'm farly new on Qt and I'm still learning how things works. Yet, I run into a problem that I cannot firgure out.

    I build a C++ application directly in consol, and now i'm trying to migrate it into Qt.
    This app is using XML file to load data and I used tinyxml2 to read all my XML file.

    In visual studio, everything is working fine as I have a XMLDoccument, XMLNode * XMLElement * etc etc.

    But once in Qt, the framework seems to have problems gather the nodes and the elements.

    here's by loading function

    void AppFileLoad(tinyxml2::XMLDocument * file, ChampionGen * genChamp, int lane)
    {
        // Initiate variables
        std::string name;
        std::string link;
        std::string value;
        int played = 0;
        int meta = 0;
        int otp = 0;
    
        // Initiate array
        std::string arrayNode[]{"name", "played", "otp", "meta", "link"};
    
        // Initiate xml elements
        tinyxml2::XMLNode* fRoot = nullptr;
        tinyxml2::XMLElement* fLane = nullptr;
        tinyxml2::XMLElement* fChampion = nullptr;
        tinyxml2::XMLElement* fAttribut = nullptr;
    
        // Set on root
        fRoot = file->FirstChildElement("root");
    
        // Set on lane
        fLane = fRoot->FirstChildElement("lane");
    
        // Check if this is the right file
        if (fLane->GetText() != IntToString(lane))
        {
            ErrorDispatcher(2, 2);
        }
    

    the XML file looks like this

    <?xml version="1.0" encoding="utf-8"?>
    <root>
        <lane>1</lane>
        <champion>
          <name>Test</name>
          <played>3</played>
          <op>0</op>
          <meta>2</meta>
          <link>Test\Matchup\1\Drmundo.xml</link>
        </champion>
    </root>
    

    The build is stopped at //Set on lane and the state of my pointer look like this
    17284b74-fe39-48be-a468-d9842ed0c42f-image.png

    so fLane cannot be set on fRoot because fRoot is null.

    At the moment I don't understand by the application doesn't set my XMLNode* fRoot as it's working on visual studio.

    I'm not sure if Qt don't like the usage of tinyxml2 or something like this and if possible I'd like to avoid changing all my function with some QXMLDocuement.

    Hope someone will be able to help me on this issue.

    Good day to all of you.

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

      There is no difference if you use MSVC or Qt/MinGW - it's both plain c++.
      Make sure you open the file correctly - esp. if the path is correct.

      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
      0
      • L Offline
        L Offline
        Louce
        wrote on last edited by
        #3

        Hi Christian.

        Thank you for the confirmation that both MSVS and Qt working on plain c++.

        Indeed there is something wrong with the file loading as I tested it.
        To be more precise on the context at the moment i'm not sure how to send objects in a Qt windows so I load my xml files directely in the window constructor ( i'm sure there are better ways to do it but didn't find it yet ).

        The path of my xml file didn't changed so i'm not sure why tinyxml2 can't access it at this point.

        Here's the tree of my files
        4c485bb2-4c00-48fc-8087-5535ba926761-image.png

        And the test that I try to make.

         tinyxml2::XMLDocument doc;
        
            // Store the result of the file loaded into an XML Error
            tinyxml2::XMLError eResult = doc.LoadFile("Test\\ChampionConfig\\1\\ChampionConfig.xml");
        
            // Check if the XML Error == to an XML_SUCESS
            if (eResult != tinyxml2::XML_SUCCESS)
            {
        
                // If not, dispatch an error 1 type 2
                std::cout << "Error" << std::endl;
            }
            else
            {
                std::cout << "Success" << std::endl;
            }
        

        The weird part is that this simple test works on MSVS so i'm still confused.

        Christian EhrlicherC 1 Reply Last reply
        0
        • L Louce

          Hi Christian.

          Thank you for the confirmation that both MSVS and Qt working on plain c++.

          Indeed there is something wrong with the file loading as I tested it.
          To be more precise on the context at the moment i'm not sure how to send objects in a Qt windows so I load my xml files directely in the window constructor ( i'm sure there are better ways to do it but didn't find it yet ).

          The path of my xml file didn't changed so i'm not sure why tinyxml2 can't access it at this point.

          Here's the tree of my files
          4c485bb2-4c00-48fc-8087-5535ba926761-image.png

          And the test that I try to make.

           tinyxml2::XMLDocument doc;
          
              // Store the result of the file loaded into an XML Error
              tinyxml2::XMLError eResult = doc.LoadFile("Test\\ChampionConfig\\1\\ChampionConfig.xml");
          
              // Check if the XML Error == to an XML_SUCESS
              if (eResult != tinyxml2::XML_SUCCESS)
              {
          
                  // If not, dispatch an error 1 type 2
                  std::cout << "Error" << std::endl;
              }
              else
              {
                  std::cout << "Success" << std::endl;
              }
          

          The weird part is that this simple test works on MSVS so i'm still confused.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Louce said in Question regarding Tinyxml2 in a Qt app.:

          doc.LoadFile("Test\ChampionConfig\1\ChampionConfig.xml");

          This is a relative path - make sure it's really relative to your current directory which is QCoreApplication::applicationDirPath() if you don't change it e.g. through QDir::setCurrent() or a low level operation.

          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
          2
          • L Offline
            L Offline
            Louce
            wrote on last edited by Louce
            #5

            Hello Christian.

            You were right, I didn't know that the application was in a different directory then the files them self.

            I'll try that and confirm that my question is resolve later.

            big thank you to you.

            EDIT : It's resolved. thanks

            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