[PyQt] Problem Loading Default QSetting
David Boddie
david at boddie.org.uk
Tue Jan 6 23:15:35 GMT 2009
On Mon, 05 Jan 2009 10:47:25 -0800, Brent Villalobos wrote:
> If I understand the documentation correctly, the
> QtCore.QSettings.value() method's second argument can be a QVariant
> default value. However, when I provide a key that does not exist, I'm
> not defaulting to that value. Observe when I try to read the settings
> for a configuration that does not exist:
> >>> from PyQt4 import QtCore
> >>> settings = QtCore.QSettings('MyComp', 'NoConfig')
> >>> settings.beginGroup('NoExist')
> >>> print settings.value("pos", QtCore.QVariant(100, 100)).toSize()
> PyQt4.QtCore.QSize(-1, -1)
>
> Why am I receiving a QSize(-1, -1) object instead of QSize(100, 100)?
Because you're actually calling the constructor of QVariant that takes
a type code and a sip.voidptr instance:
http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qvariant.html#QVariant-3
Since QVariant can accept lots of different object types, what you want to do
is pass a QSize instance to it:
print settings.value("pos", QtCore.QVariant(QtCore.QSize(100, 100))).toSize()
David
More information about the PyQt
mailing list