PDA

View Full Version : Reading XML Configuration file



beginQT
17th October 2011, 13:23
Hello,

I have an requirement in the project to read XML config file which consists of some UI window dimensions and few other information related to the Application. Example:

<Display>


<add key="Window_Width" value="800" />

<add key="Window_Height" value="600" />

</Display>

Its basically an Key Value pair config file, I need to read this values associated with the keys and need to update the window properties accordingly.

I have seen some QT classes like Qsetting and QXMLStreamReader which doesn't look like helps me reading this XML config file.

Could you please suggest me how to read and which classes to use, and any Code Examples also would be of great help.

Thanks in Advance!

saeedIRHA
17th October 2011, 18:15
Hey,
I think this tutorial would help you:
http://www.voidrealms.com/viewtutorial.aspx?id=241

good luck

wysota
17th October 2011, 18:42
What's wrong with QXmlStreamReader? You can also use QDomDocument.

beginQT
18th October 2011, 09:58
Thanks for the Link!

In all the examples these methods would take Qstrings and also returns QDomElement or something specific..I could not find the method which converts to integer because all the values I have in my config file is height and width of the window..
I know we can use typecasting to do this, but just wondering if this is how it works!

Thanks!

wysota
18th October 2011, 11:54
QString::toInt()

saeedIRHA
18th October 2011, 12:04
why don't you convert QString to Integer using this method:
QString number = "25";
bool ok; //-----> to check if the conversion was all right
int dec = number.toInt( &ok, 10); //--> 10 is base, in this case is decimal , if you need hex it has to be 16

beginQT
19th October 2011, 09:12
Yes it works! Thanks for the tutorials