KTemporaryFile

Search for usage in LXR

KTemporaryFile Class Reference

#include <KTemporaryFile>

Inheritance diagram for KTemporaryFile:

Public Member Functions

 KTemporaryFile (const KComponentData &componentData=KGlobal::mainComponent())
 
 ~KTemporaryFile () override
 
void setPrefix (const QString &prefix)
 
void setSuffix (const QString &suffix)
 
- Public Member Functions inherited from QTemporaryFile
 QTemporaryFile (const QString &templateName)
 
 QTemporaryFile (const QString &templateName, QObject *parent)
 
 QTemporaryFile (QObject *parent)
 
bool autoRemove () const const
 
virtual QString fileName () const const override
 
QString fileTemplate () const const
 
bool open ()
 
void setAutoRemove (bool b)
 
void setFileTemplate (const QString &name)
 
- Public Member Functions inherited from QFile
 QFile (const QString &name)
 
 QFile (const QString &name, QObject *parent)
 
 QFile (QObject *parent)
 
bool copy (const QString &newName)
 
bool exists () const const
 
bool moveToTrash ()
 
bool open (FILE *fh, QIODevice::OpenMode mode, QFileDevice::FileHandleFlags handleFlags)
 
bool open (int fd, QIODevice::OpenMode mode, QFileDevice::FileHandleFlags handleFlags)
 
virtual QFileDevice::Permissions permissions () const const override
 
bool remove ()
 
bool rename (const QString &newName)
 
virtual bool resize (qint64 sz) override
 
void setFileName (const QString &name)
 
virtual bool setPermissions (QFileDevice::Permissions permissions) override
 
virtual qint64 size () const const override
 
QString symLinkTarget () const const
 
- Public Member Functions inherited from QFileDevice
virtual bool atEnd () const const override
 
virtual void close () override
 
QFileDevice::FileError error () const const
 
QDateTime fileTime (QFileDevice::FileTime time) const const
 
bool flush ()
 
int handle () const const
 
virtual bool isSequential () const const override
 
uchar * map (qint64 offset, qint64 size, QFileDevice::MemoryMapFlags flags)
 
virtual qint64 pos () const const override
 
virtual bool seek (qint64 pos) override
 
bool setFileTime (const QDateTime &newDate, QFileDevice::FileTime fileTime)
 
bool unmap (uchar *address)
 
void unsetError ()
 
- Public Member Functions inherited from QIODevice
 QIODevice (QObject *parent)
 
void aboutToClose ()
 
virtual qint64 bytesAvailable () const const
 
virtual qint64 bytesToWrite () const const
 
void bytesWritten (qint64 bytes)
 
virtual bool canReadLine () const const
 
void channelBytesWritten (int channel, qint64 bytes)
 
void channelReadyRead (int channel)
 
void commitTransaction ()
 
int currentReadChannel () const const
 
int currentWriteChannel () const const
 
QString errorString () const const
 
bool getChar (char *c)
 
bool isOpen () const const
 
bool isReadable () const const
 
bool isTextModeEnabled () const const
 
bool isTransactionStarted () const const
 
bool isWritable () const const
 
QIODevice::OpenMode openMode () const const
 
qint64 peek (char *data, qint64 maxSize)
 
QByteArray peek (qint64 maxSize)
 
bool putChar (char c)
 
qint64 read (char *data, qint64 maxSize)
 
QByteArray read (qint64 maxSize)
 
QByteArray readAll ()
 
int readChannelCount () const const
 
void readChannelFinished ()
 
qint64 readLine (char *data, qint64 maxSize)
 
QByteArray readLine (qint64 maxSize)
 
void readyRead ()
 
virtual bool reset ()
 
void rollbackTransaction ()
 
void setCurrentReadChannel (int channel)
 
void setCurrentWriteChannel (int channel)
 
void setTextModeEnabled (bool enabled)
 
qint64 skip (qint64 maxSize)
 
void startTransaction ()
 
void ungetChar (char c)
 
virtual bool waitForBytesWritten (int msecs)
 
virtual bool waitForReadyRead (int msecs)
 
qint64 write (const char *data)
 
qint64 write (const char *data, qint64 maxSize)
 
qint64 write (const QByteArray &byteArray)
 
int writeChannelCount () const const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Additional Inherited Members

- Public Types inherited from QFileDevice
enum  FileError
 
enum  FileHandleFlag
 
enum  FileTime
 
enum  MemoryMapFlags
 
enum  Permission
 
- Public Types inherited from QIODevice
enum  OpenModeFlag
 
- Properties inherited from QObject
 objectName
 
- Static Public Member Functions inherited from QTemporaryFile
QTemporaryFilecreateLocalFile (const QString &fileName)
 
QTemporaryFilecreateLocalFile (QFile &file)
 
QTemporaryFilecreateNativeFile (const QString &fileName)
 
QTemporaryFilecreateNativeFile (QFile &file)
 
- Static Public Member Functions inherited from QFile
bool copy (const QString &fileName, const QString &newName)
 
QString decodeName (const char *localFileName)
 
QString decodeName (const QByteArray &localFileName)
 
QByteArray encodeName (const QString &fileName)
 
bool exists (const QString &fileName)
 
bool moveToTrash (const QString &fileName, QString *pathInTrash)
 
QFileDevice::Permissions permissions (const QString &fileName)
 
bool remove (const QString &fileName)
 
bool rename (const QString &oldName, const QString &newName)
 
bool resize (const QString &fileName, qint64 sz)
 
void setDecodingFunction (QFile::DecoderFn function)
 
void setEncodingFunction (QFile::EncoderFn function)
 
bool setPermissions (const QString &fileName, QFileDevice::Permissions permissions)
 
QString symLinkTarget (const QString &fileName)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QFile
typedef DecoderFn
 
typedef EncoderFn
 
- Public Attributes inherited from QFileDevice
 AbortError
 
 AutoCloseHandle
 
 CopyError
 
 DontCloseHandle
 
 ExeGroup
 
 ExeOther
 
 ExeOwner
 
 ExeUser
 
 FatalError
 
 FileAccessTime
 
 FileBirthTime
 
typedef FileHandleFlags
 
 FileMetadataChangeTime
 
 FileModificationTime
 
 MapPrivateOption
 
 NoError
 
 NoOptions
 
 OpenError
 
typedef Permissions
 
 PermissionsError
 
 PositionError
 
 ReadError
 
 ReadGroup
 
 ReadOther
 
 ReadOwner
 
 ReadUser
 
 RemoveError
 
 RenameError
 
 ResizeError
 
 ResourceError
 
 TimeOutError
 
 UnspecifiedError
 
 WriteError
 
 WriteGroup
 
 WriteOther
 
 WriteOwner
 
 WriteUser
 
- Public Attributes inherited from QIODevice
 Append
 
 ExistingOnly
 
 NewOnly
 
 NotOpen
 
typedef OpenMode
 
 ReadOnly
 
 ReadWrite
 
 Text
 
 Truncate
 
 Unbuffered
 
 WriteOnly
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QTemporaryFile
virtual bool open (QIODevice::OpenMode flags) override
 
- Protected Member Functions inherited from QFileDevice
virtual qint64 readData (char *data, qint64 len) override
 
virtual qint64 readLineData (char *data, qint64 maxlen) override
 
virtual qint64 writeData (const char *data, qint64 len) override
 
- Protected Member Functions inherited from QIODevice
void setErrorString (const QString &str)
 
void setOpenMode (QIODevice::OpenMode openMode)
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

Deprecated:
use QTemporaryFile

By default the filename will start with your application's name, followed by six random characters. You can call QTemporaryFile::setFileTemplate() to change that.

Porting to QTemporaryFile is simple: in apps, you can probably just use the default constructor.

In parts and plugins, you were probably passing a component data to KTemporaryFile, so instead use: QTemporaryFile(QDir::tempPath() + QLatin1Char('/') + componentData.name() + QLatin1String("XXXXXX"))

For setPrefix, change the QDir::tempPath() from the above line. For setSuffix, append it after the XXXXXX.

In the simplest case where the application was only calling setSuffix(".txt"), this becomes QTemporaryFile(QDir::tempPath() + QLatin1String("/myapp_XXXXXX.txt"))

See also
QTemporaryFile

Definition at line 52 of file ktemporaryfile.h.

Constructor & Destructor Documentation

◆ KTemporaryFile()

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 42 of file ktemporaryfile.cpp.

◆ ~KTemporaryFile()

KTemporaryFile::~KTemporaryFile ( )
override

Destructor.

Definition at line 49 of file ktemporaryfile.cpp.

Member Function Documentation

◆ setPrefix()

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 54 of file ktemporaryfile.cpp.

◆ setSuffix()

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 71 of file ktemporaryfile.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 03:56:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.