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

Paul Miller stelefx at gmail.com
Thu Sep 26 15:44:07 CEST 2013


On 9/26/2013 3:57 AM, Etienne Sandré-Chardonnal wrote:
> Then I don't see the point of QTemporaryFile... You write some data and
> can't do anything with it?
>
> What are the legacy uses of it?

I use temporary files for memory mapping points and storing undo data. 
Stuff that can get blown away when the application exits.

>   - 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?

Don't open a temporary file from another place. It doesn't make sense.

>   - 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.

When you write to that "temporary file", the FILE ITSELF is not 
temporary - just the name. Don't confuse the two. In that case you're 
writing a REAL, NON-TEMP file with a temporary name, deleting the old 
file, then renaming the new file to the proper name. This is NOT the 
same thing as a "temporary file".





More information about the Interest mailing list