Home · Overviews · Examples 

QTemporaryFile Class Reference
[com.trolltech.qt.core module]

The QTemporaryFile class is an I/O device that operates on temporary files. More...

Inherits QFile.


Detailed Description

The QTemporaryFile class is an I/O device that operates on temporary files.

QTemporaryFile is used to create unique temporary files safely. The file itself is created by calling open. The name of the temporary file is guaranteed to be unique (i.e., you are guaranteed to not overwrite an existing file), and the file will subsequently be removed upon destruction of the QTemporaryFile object. This is an important technique that avoids data corruption for applications that store data in temporary files. The file name is either auto-generated, or created based on a template, which is passed to QTemporaryFile's constructor.

Example:

    {
        QTemporaryFile file;
        if (file.open()) {
            // file.fileName() returns the unique file name
        }

        // the QTemporaryFile destructor removes the temporary file
    }

Reopening a QTemporaryFile after calling close is safe. For as long as the QTemporaryFile object itself is not destroyed, the unique temporary file will exist and be kept open internally by QTemporaryFile.

A temporary file will have some static part of the name and some part that is calculated to be unique. The default filename qt_temp will be placed into the temporary path as returned by QDir::tempPath().

See also QDir::tempPath and QFile.


Copyright © 2008 Trolltech Trademarks
Qt Jambi 4.3.4_01