• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

Public Member Functions | List of all members
KTemporaryFile Class Reference

#include <KTemporaryFile>

Inheritance diagram for KTemporaryFile:
Inheritance graph
[legend]

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:

KTemporaryFile temp;

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:

temp.setPrefix("/var/lib/foodata/");

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:

temp.setSuffix(".pdf");

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 ( !temp.open() ) {
// handle error...
}

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
Author
Jaison Lee lee.j.nosp@m.aiso.nosp@m.n@gma.nosp@m.il.c.nosp@m.om

Definition at line 92 of file ktemporaryfile.h.

Constructor & Destructor Documentation

KTemporaryFile::KTemporaryFile ( const KComponentData &  componentData = KGlobal::mainComponent())
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
componentDataThe KComponentData to use for the name of the file and to look up the directory.

Definition at line 43 of file ktemporaryfile.cpp.

KTemporaryFile::~KTemporaryFile ( )
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
prefixThe 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
suffixThe 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:
  • ktemporaryfile.h
  • ktemporaryfile.cpp
This file is part of the KDE documentation.
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.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal