Results 1 to 7 of 7

Thread: Reading XML Configuration file

  1. #1
    Join Date
    Sep 2011
    Posts
    27
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question Reading XML Configuration file

    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!

  2. #2
    Join Date
    Sep 2011
    Posts
    12
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading XML Configuration file

    Hey,
    I think this tutorial would help you:
    http://www.voidrealms.com/viewtutorial.aspx?id=241

    good luck
    Unix is simple. It just takes a genius to understand its simplicity. – Dennis Ritchie

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading XML Configuration file

    What's wrong with QXmlStreamReader? You can also use QDomDocument.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Sep 2011
    Posts
    27
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Reading XML Configuration file

    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!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading XML Configuration file

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Sep 2011
    Posts
    12
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Reading XML Configuration file

    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
    Unix is simple. It just takes a genius to understand its simplicity. – Dennis Ritchie

  7. #7
    Join Date
    Sep 2011
    Posts
    27
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Reading XML Configuration file

    Yes it works! Thanks for the tutorials

Similar Threads

  1. Replies: 0
    Last Post: 23rd May 2011, 10:01
  2. Reading XML file into a data file correctly?
    By falconium in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2011, 18:55
  3. reading network configuration
    By Tomasz in forum Newbie
    Replies: 1
    Last Post: 9th August 2010, 19:10
  4. reading a file
    By xaqt in forum Newbie
    Replies: 6
    Last Post: 14th September 2009, 15:04
  5. help in reading XML file
    By cshiva_in in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2008, 13:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.