Hello everyone, I'm trying to send a python-string via a QTcpSocket. I am using this structure:
---------------------------------------- block = QtCore.QByteArray() stream = QtCore.QTextStream(block, QtCore.QIODevice.WriteOnly) stream << myPythonString if myTcpSocket.isWritable(): myTcpSocket.write(block) ----------------------------------------- However, it now seems that there are some corrupted characters at the beginning of the bytearray (or textstream) :-S.. A solution for this can be to call stream.flush() just before I stream myPythonString to it.. In code: ---------------------------------------- block = QtCore.QByteArray() stream = QtCore.QTextStream(block, QtCore.QIODevice.WriteOnly) stream.flush() # removes the ascii dump successfully stream << myPythonString if myTcpSocket.isWritable(): print "writing data to ", str(socket.peerAddress().toString()) myTcpSocket.write(block) # crashes here ----------------------------------------- But at this point, the program crashes at the last line when actually writing to the socket.. How come? I found out that this crash can be reproduced anywhere when calling stream.string() just after streaming myPythonString to the textstream.. In code: ---------------------------------------- block = QtCore.QByteArray() stream = QtCore.QTextStream(block, QtCore.QIODevice.WriteOnly) stream.flush() # removes the ascii dump stream << myPythonString print str(stream.string()) # crashes here already.. if myTcpSocket.isWritable(): print "writing data to ", str(socket.peerAddress().toString()) myTcpSocket.write(block) ----------------------------------------- How on earth can this be? -- Nick Gaens
_______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt