PyQt中QTextStream和QDataStream混合使用问题
from PyQt4.QtCore import ( QFile, QIODevice, QDataStream, QTextStream)
myfile = QFile("1.txt")
if not myfile.open(QIODevice.WriteOnly):
print "open file failed!"
else:
myfile.setTextModeEnabled(True)
outText = QTextStream(myfile)
outText << "myname is lili!\n"
inBin = QDataStream(myfile)
inBin.writeDouble(23.454)
myfile.close()
myfile = QFile("1.txt")
if not myfile.open(QIODevice.ReadOnly):
print "open file failed!"
else:
#myfile.setTextModeEnabled(True)
outText = QTextStream(myfile)
v = outText.readLine()
print v
inBin = QDataStream(myfile)
v = inBin.readDouble()
print v
myfile.close()
目的是想在一个文件中先写入txt格式的数据,之后再写上二进制的数据,可是二进制数据总是写进了文件的开始,这是怎么回事?能这么混合使用QTextStream和QDataStream吗?
[解决办法]
只会wxPython不会pyQT的帮顶