Qt Jambi Home

com.trolltech.qt.core
Class QTemporaryFile

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.core.QIODevice
                  extended by com.trolltech.qt.core.QFile
                      extended by com.trolltech.qt.core.QTemporaryFile
All Implemented Interfaces:
QtJambiInterface

public class QTemporaryFile
extends QFile

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, QFile

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.core.QFile
QFile.FileError, QFile.Permission, QFile.Permissions
 
Nested classes/interfaces inherited from class com.trolltech.qt.core.QIODevice
QIODevice.OpenMode, QIODevice.OpenModeFlag
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 
Fields inherited from class com.trolltech.qt.core.QIODevice
aboutToClose, bytesWritten, readyRead
 
Constructor Summary
QTemporaryFile()
          Constructs a QTemporaryFile in QDir::tempPath(), using the file template "qt_temp.XXXXXX".
QTemporaryFile(QObject parent)
          Constructs a QTemporaryFile (with the given parent) in QDir::tempPath(), using the file template "qt_temp.XXXXXX".
QTemporaryFile(java.lang.String templateName)
          Constructs a QTemporaryFile with a template filename of templateName.
QTemporaryFile(java.lang.String templateName, QObject parent)
          Constructs a QTemporaryFile with a template filename of templateName and the specified parent.
 
Method Summary
 boolean autoRemove()
          Returns true if the QTemporaryFile is in auto remove mode.
static QTemporaryFile createLocalFile(QFile file)
          Creates and returns a local temporary file whose contents are a copy of the contents of the given file.
static QTemporaryFile createLocalFile(java.lang.String fileName)
          Works on the given fileName rather than an existing QFile object.
 QAbstractFileEngine fileEngine()
          This function is reimplemented for internal reasons.
 java.lang.String fileTemplate()
          Returns the set file template.
static QTemporaryFile fromNativePointer(QNativePointer nativePointer)
          This function returns the QTemporaryFile instance pointed to by nativePointer
 boolean open()
          A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, this allows easy access to the data in the file.
 boolean open(QIODevice.OpenMode flags)
          This function is reimplemented for internal reasons.
 void setAutoRemove(boolean b)
          Sets the QTemporaryFile into auto-remove mode if b is true.
 void setFileTemplate(java.lang.String name)
          Sets the static portion of the file name to name.
 java.lang.String uniqueFilename()
          Returns the complete unique filename backing the QTemporaryFile object.
 
Methods inherited from class com.trolltech.qt.core.QFile
atEnd, close, copy, copy, decodeName, decodeName, encodeName, error, exists, exists, fileName, flush, handle, isSequential, link, link, open, open, permissions, permissions, pos, readData, readLineData, remove, remove, rename, rename, resize, resize, seek, setFileName, setPermissions, setPermissions, setPermissions, setPermissions, size, symLinkTarget, symLinkTarget, unsetError, writeData
 
Methods inherited from class com.trolltech.qt.core.QIODevice
bytesAvailable, bytesToWrite, canReadLine, errorString, getByte, isOpen, isReadable, isTextModeEnabled, isWritable, open, openMode, peek, peek, putByte, read, read, readAll, readLine, readLine, readLine, reset, setErrorString, setOpenMode, setOpenMode, setTextModeEnabled, ungetByte, waitForBytesWritten, waitForReadyRead, write, write
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QTemporaryFile

public QTemporaryFile(QObject parent)

Constructs a QTemporaryFile (with the given parent) in QDir::tempPath(), using the file template "qt_temp.XXXXXX".

See Also:
setFileTemplate

QTemporaryFile

public QTemporaryFile()

Constructs a QTemporaryFile in QDir::tempPath(), using the file template "qt_temp.XXXXXX". The file is stored in the system's temporary directory.

See Also:
setFileTemplate, QDir::tempPath

QTemporaryFile

public QTemporaryFile(java.lang.String templateName,
                      QObject parent)

Constructs a QTemporaryFile with a template filename of templateName and the specified parent. Upon opening the temporary file this will be used to create a unique filename. If the templateName does end in XXXXXX it will automatically be appended and used as the dynamic portion of the filename.

If templateName is a relative path, the path will be relative to the current working directory. You can use QDir::tempPath() to construct templateName if you want use the system's temporary directory.

See Also:
open, fileTemplate

QTemporaryFile

public QTemporaryFile(java.lang.String templateName)

Constructs a QTemporaryFile with a template filename of templateName. Upon opening the temporary file this will be used to create a unique filename. If the templateName does not contain XXXXXX it will automatically be appended and used as the dynamic portion of the filename.

If templateName is a relative path, the path will be relative to the current working directory. You can use QDir::tempPath() to construct templateName if you want use the system's temporary directory.

See Also:
open, fileTemplate
Method Detail

autoRemove

public final boolean autoRemove()

Returns true if the QTemporaryFile is in auto remove mode. Auto-remove mode will automatically delete the filename from disk upon destruction. This makes it very easy to create your QTemporaryFile object on the stack, fill it with data, read from it, and finally on function return it will automatically clean up after itself.

Auto-remove is on by default.

See Also:
setAutoRemove, remove

uniqueFilename

public final java.lang.String uniqueFilename()

Returns the complete unique filename backing the QTemporaryFile object. This string is null before the QTemporaryFile is opened, afterwards it will contain the fileTemplate plus additional characters to make it unique.

See Also:
fileTemplate

fileTemplate

public final java.lang.String fileTemplate()

Returns the set file template. The default file template will be called qt_temp and be placed in QDir::tempPath().

See Also:
setFileTemplate

open

public final boolean open()

A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, this allows easy access to the data in the file. This function will return true upon success and will set the fileName to the unique filename used.

See Also:
fileName

setAutoRemove

public final void setAutoRemove(boolean b)

Sets the QTemporaryFile into auto-remove mode if b is true.

Auto-remove is on by default.

See Also:
autoRemove, remove

setFileTemplate

public final void setFileTemplate(java.lang.String name)

Sets the static portion of the file name to name. If the file template ends in XXXXXX that will automatically be replaced with the unique part of the filename, otherwise a filename will be determined automatically based on the static portion specified.

If name contains a relative file path, the path will be relative to the current working directory. You can use QDir::tempPath() to construct name if you want use the system's temporary directory.

See Also:
fileTemplate

fileEngine

public QAbstractFileEngine fileEngine()

This function is reimplemented for internal reasons.

Overrides:
fileEngine in class QFile

open

public boolean open(QIODevice.OpenMode flags)

This function is reimplemented for internal reasons.

Overrides:
open in class QFile
See Also:
QIODevice::OpenMode, setFileName

createLocalFile

public static QTemporaryFile createLocalFile(QFile file)

Creates and returns a local temporary file whose contents are a copy of the contents of the given file.


createLocalFile

public static QTemporaryFile createLocalFile(java.lang.String fileName)

Works on the given fileName rather than an existing QFile object.


fromNativePointer

public static QTemporaryFile fromNativePointer(QNativePointer nativePointer)
This function returns the QTemporaryFile instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

Qt Jambi Home