KTemporaryFile
#include <KTemporaryFile>

Public Member Functions | |
KTemporaryFile (const KComponentData &componentData=KGlobal::mainComponent()) | |
~KTemporaryFile () override | |
void | setPrefix (const QString &prefix) |
void | setSuffix (const QString &suffix) |
![]() | |
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) |
![]() | |
QFile (const QString &name) | |
QFile (const QString &name, QObject *parent) | |
QFile (QObject *parent) | |
bool | copy (const QString &newName) |
bool | exists () const const |
bool | link (const QString &linkName) |
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 |
QString | readLink () const const |
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 |
![]() | |
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 () |
![]() | |
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 |
![]() | |
QObject (QObject *parent) | |
bool | blockSignals (bool block) |
const QObjectList & | children () 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< QByteArray > | dynamicPropertyNames () const const |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, 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 QMetaObject * | metaObject () const const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const const |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () 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 | |
T | qFindChild (const QObject *obj, const QString &name) |
QList< T > | qFindChildren (const QObject *obj, const QRegExp ®Exp) |
QList< T > | qFindChildren (const QObject *obj, const QString &name) |
T | qobject_cast (const QObject *object) |
T | 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) |
QThread * | thread () const const |
Additional Inherited Members | |
![]() | |
enum | FileError |
enum | FileHandleFlag |
enum | FileTime |
enum | MemoryMapFlags |
enum | Permission |
![]() | |
enum | OpenModeFlag |
![]() | |
objectName | |
![]() | |
QTemporaryFile * | createLocalFile (const QString &fileName) |
QTemporaryFile * | createLocalFile (QFile &file) |
QTemporaryFile * | createNativeFile (const QString &fileName) |
QTemporaryFile * | createNativeFile (QFile &file) |
![]() | |
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 | link (const QString &fileName, const QString &linkName) |
bool | moveToTrash (const QString &fileName, QString *pathInTrash) |
QFileDevice::Permissions | permissions (const QString &fileName) |
QString | readLink (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) |
![]() | |
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) |
![]() | |
typedef | DecoderFn |
typedef | EncoderFn |
![]() | |
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 | |
![]() | |
Append | |
ExistingOnly | |
NewOnly | |
NotOpen | |
typedef | OpenMode |
ReadOnly | |
ReadWrite | |
Text | |
Truncate | |
Unbuffered | |
WriteOnly | |
![]() | |
typedef | QObjectList |
![]() | |
virtual bool | open (QIODevice::OpenMode flags) override |
![]() | |
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 |
![]() | |
void | setErrorString (const QString &str) |
void | setOpenMode (QIODevice::OpenMode openMode) |
![]() | |
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 |
QObject * | sender () const const |
int | senderSignalIndex () const const |
virtual void | timerEvent (QTimerEvent *event) |
Detailed Description
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()
|
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 42 of file ktemporaryfile.cpp.
◆ ~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
-
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 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
-
suffix The 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:
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.