[PyQt] Pickle a QPolygon in python 3.6+ and PyQt5

Phil Thompson phil at riverbankcomputing.com
Wed Mar 6 11:47:46 GMT 2019


On 1 Mar 2019, at 9:32 am, William Hoburg <Howil at gmx.net> wrote:
> 
> Hallo,
>  
> I think there is a bug regarding the use of QPolygon with pickel. Due to documentation (http://pyqt.sourceforge.net/Docs/PyQt5/pickle.html) using pickle with QPolygon is supported but I get an error. 
>  
> I posted the following request on stackoverflow (please see https://stackoverflow.com/questions/54928431/pickle-a-qpolygon-in-python-3-6-and-pyqt5) and was asked to write a bug report.
>  
> Here the following request from stackoverflow including a simple example:
> I try to pickle a QPolygon and load it afterwards, but I get an error. I have done this on Python2 with PyQt4 but want to use it now on Python3 with PyQt5.
> 
> I do not want to read/load data generated with Python 2! The pickle file is simply used to temporarily store Qt-elements like QPolygons from Python3 to Python3.
> 
> I have tested different protocol options from 1-4 for pickle.dump() and tried to use the "fix_imports=True" option which should not make a difference in Python3.
> 
> Here is my simplified code:
> 
> #####################################
> from PyQt5.QtGui import QPolygon
> from PyQt5.QtCore import QPoint
> import pickle
> 
> file_name = "test_pickle.chip"
> 
> with open(file_name, 'wb') as f:
>     poly = QPolygon((QPoint(1, 1), QPoint(2, 2))) 
>     pickle.dump(poly, f, protocol=2)  # , fix_imports=True)
> 
> # loading the data again
> with open(file_name, 'rb') as f:
>     elem = pickle.load(f, encoding='bytes')  # , fix_imports=True)
> 
> #####################################
>  
>  
> I get the following error message but can't do anything with it:
> elem = pickle.load(f, encoding='bytes')  # , fix_imports=True)
> TypeError: index 0 has type 'int' but 'QPoint' is expected
> 
>  
>  
>  
> Is there maybe any alternative to pickle which can be used to easily store different types of data like strings, QPolygones and so on?

Should be fixed in tonight's PyQt5 snapshot.

Thanks,
Phil



More information about the PyQt mailing list