[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Casting from QSettings
From:       Prafulla Kiran <prafulla () tachyontech ! net>
Date:       2009-11-25 17:14:29
Message-ID: 4B0D6325.8010008 () tachyontech ! net
[Download RAW message or body]


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
>
>   

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic