<div>ÔÚ2010-02-03&nbsp;17:41:17£¬"Phil&nbsp;Thompson"&nbsp;&lt;phil@riverbankcomputing.com&gt;&nbsp;дµÀ£º
&gt;On&nbsp;Wed,&nbsp;3&nbsp;Feb&nbsp;2010&nbsp;10:31:44&nbsp;+0800&nbsp;(CST),&nbsp;donglongchao
&gt;&lt;donglongchao@163.com&gt;
&gt;wrote:
&gt;&gt;&nbsp;Hi,all
&gt;&gt;&nbsp;
&gt;&gt;&nbsp;I&nbsp;am&nbsp;newbie&nbsp;to&nbsp;PyQt&nbsp;and&nbsp;I&nbsp;have&nbsp;a&nbsp;question&nbsp;when&nbsp;I&nbsp;work&nbsp;on&nbsp;my&nbsp;app&nbsp;with
&gt;PyQt.
&gt;&gt;&nbsp;I&nbsp;want&nbsp;to&nbsp;use&nbsp;a&nbsp;QDataStream&nbsp;to&nbsp;form&nbsp;a&nbsp;QHash&nbsp;object&nbsp;into&nbsp;a&nbsp;QByteArray&nbsp;and
&gt;&gt;&nbsp;write&nbsp;it&nbsp;into&nbsp;a&nbsp;QTcpSocket.But&nbsp;there&nbsp;is&nbsp;an&nbsp;error&nbsp;when&nbsp;I&nbsp;run&nbsp;my&nbsp;app&nbsp;said&nbsp;
&gt;&gt;&nbsp;NameError:&nbsp;global&nbsp;name&nbsp;'QHash'&nbsp;is&nbsp;not&nbsp;defined.I&nbsp;have&nbsp;import&nbsp;everything
&gt;from
&gt;&gt;&nbsp;QtCore&nbsp;and&nbsp;QtGui.Also&nbsp;I&nbsp;can&nbsp;locate&nbsp;qhash.sip&nbsp;in&nbsp;my&nbsp;computer
&gt;&gt;&nbsp;(/usr/share/sip/PyQt4/QtCore/qhash.sip).So&nbsp;I&nbsp;want&nbsp;to&nbsp;know&nbsp;wherer&nbsp;is&nbsp;the
&gt;&gt;&nbsp;problem&nbsp;and&nbsp;how&nbsp;to&nbsp;use&nbsp;QHash&nbsp;here.
&gt;
&gt;In&nbsp;C++&nbsp;QHash&nbsp;is&nbsp;a&nbsp;template.&nbsp;For&nbsp;the&nbsp;classes&nbsp;that&nbsp;Qt&nbsp;provides&nbsp;a&nbsp;qHash()
&gt;implementation,&nbsp;PyQt&nbsp;implements&nbsp;the&nbsp;__hash__&nbsp;method&nbsp;so&nbsp;that&nbsp;hash()&nbsp;returns
&gt;the&nbsp;value&nbsp;that&nbsp;qHash()&nbsp;returns.<br><br>But I still do not know how to create an object like QHash&lt;int,QString&gt;.I checked the file qhash.sip and find that <br>&nbsp;QHash&lt;TYPE1, TYPE2&gt; is implemented as a Python dictionary.So is it possible to convert a dict object into a QHash&lt;TYPE1,TYPE2&gt; object?Because I can not use a dict object with QDataStream's operator "&lt;&lt;" directly.<br>Thanks a lot.<br><br>Longchao<br>&nbsp;&gt;
&gt;Phil
</div><br><br><span title="neteasefooter"/></span>