I'm building a PyQt app and I'm quite beginner with python. Let's say I store an obj item in a 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 I work through a GUI perform other operation and create a list of Items. How can I save this list so that I can open it later ? pickle does not work with QPixmap and I'd like to save a single.
You can use QSettings to save all your application data. It will automatically convert data types like
QPixmap
,QPoint
,QColor
, etc. By default, the settings are saved in a platform-independant way, but you can also save to a custom location if you want.Here is how you could read/write your
Item
class:The PyQt version of
QSettings.value()
allows you to specify both a default value and the expected type of the value.