[PyQt] Casting from QSettings

Prafulla Kiran prafulla at tachyontech.net
Wed Nov 25 17:02:29 GMT 2009


Hi Lokev,

According to the Qt API docs, QVariant's toInt method returns a tuple 
with the first field being the value and
the second field  - a boolean indicating whether or not the casting went 
fine. Hence you would have to use

settings.value("MoneySpent", 0).toInt()[0]   to retrieve the int value

Regards,
Prafulla

lokev wrote:
> Hi Guys .. PyQt-noob .. and this is driving me nuts .. probably easy to sort
> though ..
>
> So I'm saving ints in a QSettings instance .. like this ..
> def closeEvent(self, event):
>     settings = QSettings()
>     settings.setValue("MoneySpent", self.moneySpent)
>     
> and I'm loading this in init ..
>
> def __init__(self, parent=None):
>     settings = QSettings()
>     self.moneySpent = settings.value("MoneySpent", 0).toInt()
>
> but then the type of self.moneySpent is a tuple, not an int, so when i later
> try
>
>     self.moneySpent += 50
>
> i get:
> TypeError: can only concatenate tuple (not "int") to tuple ...
>
> ... soooo ? Why does "settings.value("MoneySpent", 0).toInt()" set the type
> of self.moneySpent to tuple .... ?
>
> I appreciate any help i can get to sort this out .. :)
>
> - lokev
>
>
>   
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com 
> Version: 8.5.425 / Virus Database: 270.14.82/2525 - Release Date: 11/25/09 07:31:00
>
>   



More information about the PyQt mailing list