[PyQt] Small problem storing a list in QSettings

Phil Thompson phil at riverbankcomputing.com
Sun Sep 4 16:43:35 BST 2011


On Sun, 4 Sep 2011 17:25:56 +0200, Andreas Pakulat <apaku at gmx.de> wrote:
> On 02.09.11 16:12:49, Phil Thompson wrote:
>> On Thu, 1 Sep 2011 23:04:06 +0200, Andreas Pakulat <apaku at gmx.de>
wrote:
>> > Hi,
>> > 
>> > I'm facing a small problem with QSettings and storing a python list
in
>> > it. It seems that I can't store an empty list properly into a
QSettings
>> > object, its always converted to an invalid QVariant somewhere along
the
>> > way. The attached sample script shows this, all is well until I
create
>> > a
>> > new QSettings object from the file and try to get the list again. The
>> > printout of the ini file also shows this.
>> > 
>> > Specifying the type for the value() call does not work, that raises
an
>> > error that the conversion of the QVariant does not work due to
>> > different
>> > typeids (0 vs.  256).
>> > 
>> > Am I doing something wrong or do I really need to serialize the list
>> > manually into a string? (Can't even use QStringList here since thats
>> > not
>> > available with the v2 API).
>> > 
>> > sip: 4.12.1
>> > PyQt: 4.8.3
>> > Qt: 4.7.3
>> 
>> The problem with specifying an explicit type should be fixed in
tonight's
>> snapshot.
> 
> Ok, but what about the @Invalid being stored if I give
> QSettings.setValue an empty list as value? Is that expected?

Yes because PyQt has no idea what it might be a list of.

Phil


More information about the PyQt mailing list