<p dir="ltr"><br>
Den 19 juni 2017 9:09 em skrev "Christopher Probst" <<a href="mailto:christop.probst@gmail.com">christop.probst@gmail.com</a>>:<br>
><br>
> Hi,<br>
><br>
> I am exploring interfacing of files with QDataStream. But it does not seem to work. To write to a file I do this:<br>
><br>
><br>
> file = QFile("file.dat")<br>
> color = QColor(Qt.red)<br>
><br>
> if file.open(QIODevice.WriteOnly):<br>
>  out = QDataStream(file)<br>
>  out << color<br>
>  file.flush()<br>
>  file.close()<br>
><br>
> It looks as if that the data gets written to the file. It is the reading where there is a problem:<br>
><br>
> file = QFile("file.dat")<br>
> color = QVariant()<br>
><br>
><br>
> if file.open(QIODevice.ReadOnly):<br>
>  out = QDataStream(file)<br>
>  out >> color</p>
<p dir="ltr">I haven't used QDataStream with PyQt, but this looks strange to me: How will it know that it's a QColor you want to deserialise if color is a QVariant? I think it needs to be a QColor for there to be any chance of this working.</p>
<p dir="ltr">Hope that helps.</p>
<p dir="ltr">Elvis</p>
<p dir="ltr">>  print(color)<br>
>  print(color.value())<br>
><br>
> The output is: <br>
><br>
> <PyQt5.QtCore.QVariant object at 0x7f2cdd556f28> None<br>
><br>
> What am I doing wrong?<br>
><br>
> Thanks, Christopher<br>
><br>
><br>
><br>
><br>
> _______________________________________________<br>
> PyQt mailing list    <a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br>
> <a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br></p>