Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. [Moved] How to use QSettings to read and write from xml file?
QtWS25 Last Chance

[Moved] How to use QSettings to read and write from xml file?

Scheduled Pinned Locked Moved Language Bindings
9 Posts 5 Posters 7.6k 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.
  • M Offline
    M Offline
    ManasQt
    wrote on last edited by
    #1

    Hi All,
    please tell me how to save and read current QMainWindow settings to/from a xml file.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      As far as I know there is no built-in solution. But it can be done easily using "QXmlStreamReader":http://doc.qt.nokia.com/latest/qxmlstreamreader.html, "QXmlStreamWriter":http://doc.qt.nokia.com/latest/qxmlstreamwriter.html and "QSettings::registerFormat()":http://doc.qt.nokia.com/stable/qsettings.html#registerFormat.

      There are even implementations on the internet "here":http://www.openshots.de/2011/03/qsettings-mit-xml-format/ and "here":http://pastebin.com/M6Lqac91. No testing. No warranty.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #3

        You can also look at QMainWindow's "saveState,":http://doc.qt.nokia.com/4.7-snapshot/qmainwindow.html#saveState "restoreState,":http://doc.qt.nokia.com/4.7-snapshot/qmainwindow.html#restoreState "saveGeometry,":http://doc.qt.nokia.com/4.7-snapshot/qwidget.html#saveGeometry and "restoreGeometry.":http://doc.qt.nokia.com/4.7-snapshot/qwidget.html#restoreGeometry

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          ManasQt
          wrote on last edited by
          #4

          Hi Lukas,
          Well the version that have

          PySide version: 1.0.2

          PySide.QtCore version: 4.7.2

          PySide.QtCore.qVersion :4.7.2

              *QtCore.QSettings.registerFormat() - is missing*
          

          please tell me what should i do?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            When using Python you are probably hosed because there is no registerFormat (as you already figured out).

            1 Reply Last reply
            0
            • M Offline
              M Offline
              ManasQt
              wrote on last edited by
              #6

              Hi,

              So you mean there is no alternative way to save/read setting from XML?
              If yes ,please let me know
              please put me in the right direction.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #7

                I have to admit that I'm no Python expert but no, I don't think there is any convenient way to use QSettings with XML files. You might re-post this question directly at "PySide":http://www.pyside.org/support/.

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  uranusjr
                  wrote on last edited by
                  #8

                  Python has its own XML parsing modules, and all of them are pretty good. As PySide generally uses native Python types (lists, dicts, Python strings, etc.) for most of the data interchanging, using a native Python parser instead of QSettings does not really affect the rest of the codes, so I think you might just ditch QSettings in this case.

                  If you intends to do some lite-weight parsing, the default Python installation comes with xml.etree.ElementTree, which is very easy to use.

                  If you are not satisfied with ElementTree's performance, you can also take a look at lxml.etree, which is considered by many as the best parser around (for Python).

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    The QSettings API basically just provides a sectioned list of key-value pairs. Why would you want to use it to interact with a possibly deeply nested hierarchical structure like XML? Even if it is possible to do so (I found out that it is not trivial), the API just isn't a very good match for it.

                    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