Question regarding Tinyxml2 in a Qt app.
-
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
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.
-
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. -
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
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.
-
@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.