i'm building pyqt app , i'm quite beginner python. let's store obj item in defined class:
class item (self): def __init__(self, item_nbr, crop_pixmap, originepoint, designation): self.item_nbr = item_nbr # integer self.crop_pixmap = crop_pixmap # qpixmap self.origin_point = originpoint # qpoint self.designation = designation # str
then work through gui perform other operation , create list of items. how can save list can open later ? pickle not work qpixmap , i'd save single.
you can use qsettings save application data. automatically convert data types qpixmap
, qpoint
, qcolor
, etc. default, settings saved in platform-independant way, can save custom location if want.
here how read/write item
class:
def settings(self): # use custom location return qtcore.qsettings('app.conf', qtcore.qsettings.iniformat) def readsettings(self): self.items = [] settings = self.settings() index in range(settings.beginreadarray('items')): settings.setarrayindex(index) self.items.append(item( settings.value('number', -1, int), settings.value('pixmap', none, qtgui.qpixmap), settings.value('point', none, qtcore.qpoint), settings.value('designation', '', str), )) def writesettings(self): settings = self.settings() settings.beginwritearray('items') index, item in enumerate(self.items): settings.setarrayindex(index) settings.setvalue('number', item.item_nbr) settings.setvalue('pixmap', item.crop_pixmap) settings.setvalue('point', item.origin_point) settings.setvalue('designation', item.designation) settings.endarray()
the pyqt version of qsettings.value()
allows specify both default value , expected type of value.
Comments
Post a Comment