[Moved] How to use QSettings to read and write from xml file?
-
wrote on 1 Sept 2011, 15:04 last edited by
Hi All,
please tell me how to save and read current QMainWindow settings to/from a xml file. -
wrote on 1 Sept 2011, 15:33 last edited by
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.
-
wrote on 1 Sept 2011, 15:51 last edited by
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
-
wrote on 1 Sept 2011, 15:54 last edited by
Hi Lukas,
Well the version that havePySide 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?
-
wrote on 1 Sept 2011, 16:08 last edited by
When using Python you are probably hosed because there is no registerFormat (as you already figured out).
-
wrote on 1 Sept 2011, 16:14 last edited by
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. -
wrote on 1 Sept 2011, 16:17 last edited by
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/.
-
wrote on 12 Sept 2011, 18:40 last edited by
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).
-
wrote on 13 Sept 2011, 09:31 last edited by
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.