[Interest] QTemporaryFile::open(OpenMode flags) is protected, but not in documentation

Thiago Macieira thiago.macieira at intel.com
Thu Sep 26 18:50:27 CEST 2013


On quinta-feira, 26 de setembro de 2013 10:57:46, Etienne Sandré-Chardonnal 
wrote:
> Hi Thiago,
> 
> Then I don't see the point of QTemporaryFile... You write some data and
> can't do anything with it?

As others have answered, as long as you don't close it, you can get the data 
back.

Also, it's always secure to pass the open file descriptor to other processes. 
Passing the file name is not secure on Unix, but is on Windows (you can delete 
an open file on Unix, but not on Windows).

> What are the legacy uses of it?
>  - Open the file with a QFile for reading. Such use would be a large buffer
> we do not want to keep in memory. But according to what you said, it must
> be done before the QTemporaryFile was closed. Then, what guarantees the
> writes have been flushed?

There's flush() to ensure that it gets flushed.

Like I said above, if you reopen the same file *name* and you're in a hostile 
environment, you must assume that the file was deleted and recreated with 
different contents before you managed to reopen it. On Unix, that applies 
*even* if your QTemporaryFile is still open.

In other words, if your software runs on Unix, if you open the same file *name* 
twice, you may get two different files.

>  - Write data to a temporary file before renaming it to the final name.
> This is useful when a user saves a document overwriting the old version, in
> case the system or app crashes he does not loose all the work. But
> QFile::rename() closes before renaming, which means according to what you
> said the data is not guaranteed to be still there.

There's a class for this. It's called QSaveFile.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130926/76ab78bc/attachment.sig>


More information about the Interest mailing list