KDECore
#include <KTemporaryFile>
Public Member Functions | |
KTemporaryFile (const KComponentData &componentData=KGlobal::mainComponent()) | |
virtual | ~KTemporaryFile () |
void | setPrefix (const QString &prefix) |
void | setSuffix (const QString &suffix) |
Detailed Description
A QTemporaryFile that will save in the KDE temp directory.
This class derives from QTemporaryFile and makes sure that your temporary files go in the temporary directory defined by KDE. (This is retrieved by using KStandardDirs to locate the "tmp" resource.) In general, whenever you would use a QTemporaryFile() use a KTemporaryFile() instead.
By default the filename will start with your application's instance name, followed by six random characters and an extension of ".tmp". You can use setPrefix() and setSuffix() to change the beginning and ending of the random name, as well as change the directory if you wish (read the descriptions of these functions for more information). For complex specifications, you may be better off calling QTemporaryFile::setFileTemplate() directly.
For example, let's make a new temporary file:
This temporary file will currently be stored in the default KDE temporary directory and have an extension of ".tmp". Now, let's change the directory:
Now the temporary file will be stored in "/var/lib/foodata" instead of the default KDE temporary directory, with an extension of ".tmp". It's important to remember the leading and trailing slashes to properly define the path! Next, let's change the suffix to a particular extension:
Now the temporary file will be stored in "/var/lib/foodata" and have an extension of ".pdf" instead of ".tmp".
Once you are done determining the name of the file, call open() to create the file.
If open() is unable to create the file it will return false. If the call to open() returns true you are ready to use your temporary file. If you don't want the file removed automatically when the KTemporaryFile object is destroyed, you need to call setAutoRemove(false), but make sure you have a good reason for leaving your temp files around.
- See also
- QTemporaryFile
Definition at line 92 of file ktemporaryfile.h.
Constructor & Destructor Documentation
|
explicit |
Construct a new KTemporaryFile.
The file will be stored in the temporary directory configured in KDE. The default prefix is the value of the default KDE temporary directory, plus your application's instance name. The default suffix is ".tmp".
- Parameters
-
componentData The KComponentData to use for the name of the file and to look up the directory.
Definition at line 43 of file ktemporaryfile.cpp.
|
virtual |
Destructor.
Definition at line 50 of file ktemporaryfile.cpp.
Member Function Documentation
void KTemporaryFile::setPrefix | ( | const QString & | prefix | ) |
Sets a prefix to use when creating the file.
This function sets a prefix to use when creating the file. The random part of the filename will come after this prefix. The prefix can also change or modify the target directory. If prefix
is an absolute path it will override the default temporary directory. If prefix
is a relative directory it will be relative to the default temporary location. To set a relative directory for the current working directory you should use QTemporaryFile::setFileTemplate() directly.
- Parameters
-
prefix The prefix to use when creating the file. Remember to end the prefix with a '/' if you are designating a directory.
Definition at line 55 of file ktemporaryfile.cpp.
void KTemporaryFile::setSuffix | ( | const QString & | suffix | ) |
Sets a suffix to use when creating the file.
Sets a suffix to use when creating the file. The random part of the filename will come before this suffix.
- Parameters
-
suffix The suffix to use when creating the file.
Definition at line 72 of file ktemporaryfile.cpp.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.