Results 1 to 5 of 5

Thread: Storing window geometry inside XML file.

  1. #1
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Storing window geometry inside XML file.

    Hi guys!

    I wanted to know how to store the window geometry inside a XML file.

    Actually i use QSettings, but i want to change to XML since i already have an xml preferences file on my application (made using QDom). So, i want to store the window geometry in there too.

    Anyone could help me?

    Thanks.

    Cheers.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing window geometry inside XML file.

    I guess you know how to populate the QDomDocument

    You can use QDomDocument::toString to get the string, and I hope saving a string in a file is not a tedious task

  3. #3
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: Storing window geometry inside XML file.

    Yep.. but... mmm, in this case what i need is: write text on an existing tag, since i already have the tag created (using a method inside the xml implementation)

    So, i must search the tag (I believe is with elementsByTagName) but then i don't know how to write in it. I know what i have to write, which is QVariant(self.saveGeometry()).

    Sorry... but i am newbie in Qt and development world yet...

    I will appreciate some help.

    Thanks.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing window geometry inside XML file.

    Well for a hint you can open some ui file in Wordpad and see how it stores geometry.

    In a simple way you can create a tag like this -

    Qt Code:
    1. <Window id="1">
    2. <Geometry x="" y="" width ="" height="" />
    3. </Window>
    To copy to clipboard, switch view to plain text mode 

    For creating tags, you can use 2 ways -
    1) Write xml content into a string and use QDomDocument.setContent()
    2) Create each tag using QDomDocument::createElement(), and QDomElement::setAttribute().

    Hope u can find ur way now

  5. #5
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: Storing window geometry inside XML file.

    Hi,

    Thank for the reply

    Mmm thats looks like a nice idea, but i already know how to create tags inside xml... (which is not my problem in this case...)

    The tag for the Window geometry is being created inside a method which i've created all necesary tag with their strings data inside, except for the window Geometry one that i create am empty string (so i could later write the window geometry at close event of my application)

    My problem is, how to write inside an existing tag. I don't want to recreate the tag again, since already exist. But only modify the string of that tag every time i execute the close event (and not creating the hole xml documment, only creating or replacing the string inside the needed Tag)

    What i did yesterday was:

    Qt Code:
    1. self.file = QFile('preferences.xml')
    2. self.file.open(QIODevice.ReadOnly)
    3. self.doc = QDomDocument("OpenCoffeePreferences")
    4. self.doc.setContent(self.file)
    5. self.file.close()
    6.  
    7.  
    8. self.docElem = self.doc.documentElement()
    9. self.node = self.docElem.firstChild()
    10.  
    11. while (self.node.isNull() == False):
    12. self.element = self.node.toElement()
    13. if (self.element.isNull() == False):
    14. if (self.element.tagName() == "windowGeometry"):
    15.  
    16. self.text = self.doc.createTextNode(QVariant(self.saveGeometry()).toString())
    17. self.element.appendChild(self.text)
    18. self.node = self.node.nextSibling()
    19.  
    20. self.file.open(QIODevice.WriteOnly)
    21. self.file.write(self.doc.toString().toAscii())
    22. self.file.close()
    To copy to clipboard, switch view to plain text mode 

    But I dont know if this is right. What stores inside the xml is garbarge, like binary garbage.
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

Similar Threads

  1. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 07:51
  2. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 16:21

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.