<div dir="ltr">Hi,<div><br></div><div>I am exploring interfacing of files with QDataStream. But it does not seem to work. To write to a file I do this:</div><div><span id="gmail-docs-internal-guid-16892120-c1bc-3d7c-18bd-a2f3b94e7f7e"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:13pt;font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><br></span></p><pre style="color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:11.4pt">file = QFile(<span style="color:rgb(0,128,128);font-weight:bold">"file.dat"</span>)<br>color = QColor(Qt.red)<br><br><span style="color:rgb(0,0,128);font-weight:bold">if </span>file.open(QIODevice.WriteOnly):<br>   out =  QDataStream(file)<br>   out << color<br>   file.flush()<br>   file.close()<br></pre><p style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="background-color:transparent;font-size:13pt;font-family:Arial;color:rgb(128,128,128);font-style:italic;vertical-align:baseline;white-space:pre-wrap"><span style="color:rgb(0,0,0);font-size:17.3333px;font-style:normal">It looks as if that the data gets written to the file. It is the reading where there is a problem:

</span></span></p><pre style="color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:11.4pt">file = QFile(<span style="color:rgb(0,128,128);font-weight:bold">"file.dat"</span>)<br>color = QVariant()<br><br><br><span style="color:rgb(0,0,128);font-weight:bold">if </span>file.open(QIODevice.ReadOnly):<br>   out = QDataStream(file)<br>   out >> color<br>   <span style="color:rgb(0,0,128)">print</span>(color)<br>   <span style="color:rgb(0,0,128)">print</span>(color.value())<br></pre><pre style="color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:11.4pt"><pre style="font-family:"DejaVu Sans Mono";font-size:11.4pt">The output is: </pre></pre><pre style="color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:11.4pt"><PyQt5.QtCore.QVariant object at 0x7f2cdd556f28>
None</pre><pre style="color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:11.4pt">What am I doing wrong?</pre><pre style="color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:11.4pt">Thanks,
Christopher</pre><pre style="color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:11.4pt"><br></pre><pre style="color:rgb(0,0,0);font-family:"DejaVu Sans Mono";font-size:11.4pt"></pre><p style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="background-color:transparent;font-size:13pt;font-family:Arial;color:rgb(128,128,128);font-style:italic;vertical-align:baseline;white-space:pre-wrap"><span style="color:rgb(0,0,0);font-size:17.3333px;font-style:normal">
</span></span></p><p style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:13pt;font-family:Arial;color:rgb(128,128,128);background-color:transparent;font-style:italic;vertical-align:baseline;white-space:pre-wrap">  </span></p><div><span style="font-size:13pt;font-family:Arial;color:rgb(128,128,128);background-color:transparent;font-style:italic;vertical-align:baseline;white-space:pre-wrap"><br></span></div></span></div></div>