If you want to force the OS to write the data to a file you should always flush()
:
In [10]: from PyQt4 import QtCore
In [11]: fileTemp = QtCore.QTemporaryFile()
In [12]: fileTemp.open()
Out[12]: True
In [13]: fileTemp.fileName()
Out[13]: PyQt4.QtCore.QString(u'/tmp/qt_temp.XM5599')
In [14]: fileTemp.writeData('foobar')
Out[14]: 6L
In [15]: with open(fileTemp.fileName(), 'r') as f:
....: print(f.read())
....:
In [16]: fileTemp.flush()
Out[16]: True
In [17]: with open(fileTemp.fileName(), 'r') as f:
print(f.read())
....:
foobar
Probably the call to size()
implicitly forces the OS to flush, hence the behaviour you have observed.