Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QTemporaryFile Class Reference
[QtCore module]

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

#include <QTemporaryFile>

Inherits QFile.

Note: All the functions in this class are reentrant.

Public Functions

  • 21 public functions inherited from QFile
  • 32 public functions inherited from QIODevice
  • 28 public functions inherited from QObject

Static Public Members

  • 14 static public members inherited from QFile
  • 4 static public members inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 3 signals inherited from QIODevice
  • 1 signal inherited from QObject
  • 5 protected functions inherited from QIODevice
  • 7 protected functions inherited from QObject

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.


Member Function Documentation

QTemporaryFile::QTemporaryFile ()

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

See also setFileTemplate().

QTemporaryFile::QTemporaryFile ( const QString & 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 end in XXXXXX it will automatically be appended and used as the dynamic portion of the filename.

See also open() and fileTemplate().

QTemporaryFile::QTemporaryFile ( QObject * parent )

Constructs a QTemporaryFile with the given parent, but with no name.

See also setFileTemplate().

QTemporaryFile::QTemporaryFile ( const QString & 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.

See also open() and fileTemplate().

QTemporaryFile::~QTemporaryFile ()

Destroys the temporary file object, the file is automatically closed if necessary and if in auto remove mode it will automatically delete the file.

See also autoRemove().

bool QTemporaryFile::autoRemove () const

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() and remove().

QTemporaryFile * QTemporaryFile::createLocalFile ( QFile & file )   [static]

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

QTemporaryFile * QTemporaryFile::createLocalFile ( const QString & fileName )   [static]

This is an overloaded member function, provided for convenience.

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

QString QTemporaryFile::fileName () const

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

QString QTemporaryFile::fileTemplate () const

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

See also setFileTemplate().

bool QTemporaryFile::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().

void QTemporaryFile::setAutoRemove ( bool b )

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

Auto-remove is on by default.

See also autoRemove() and remove().

void QTemporaryFile::setFileTemplate ( const QString & 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.

See also fileTemplate().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 42
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 7
Page suivante

Le blog Digia au hasard

Logo

Créer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut Cuvelier

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.1
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web