File indexing completed on 2026-01-08 10:24:18
0001
0002
0003
0004
0005 #ifndef QTEMPORARYFILE_H
0006 #define QTEMPORARYFILE_H
0007
0008 #include <QtCore/qiodevice.h>
0009 #include <QtCore/qfile.h>
0010
0011 #ifdef open
0012 #error qtemporaryfile.h must be included before any header file that defines open
0013 #endif
0014
0015 QT_BEGIN_NAMESPACE
0016
0017
0018 #if QT_CONFIG(temporaryfile)
0019
0020 class QTemporaryFilePrivate;
0021 class QLockFilePrivate;
0022
0023 class Q_CORE_EXPORT QTemporaryFile : public QFile
0024 {
0025 #ifndef QT_NO_QOBJECT
0026 Q_OBJECT
0027 #endif
0028 Q_DECLARE_PRIVATE(QTemporaryFile)
0029
0030 public:
0031 QTemporaryFile();
0032 explicit QTemporaryFile(const QString &templateName);
0033 #ifndef QT_NO_QOBJECT
0034 explicit QTemporaryFile(QObject *parent);
0035 QTemporaryFile(const QString &templateName, QObject *parent);
0036
0037 # if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
0038 Q_WEAK_OVERLOAD
0039 explicit QTemporaryFile(const std::filesystem::path &templateName, QObject *parent = nullptr)
0040 : QTemporaryFile(QtPrivate::fromFilesystemPath(templateName), parent)
0041 {
0042 }
0043 # endif
0044 #endif
0045
0046 ~QTemporaryFile();
0047
0048 bool autoRemove() const;
0049 void setAutoRemove(bool b);
0050
0051
0052 QFILE_MAYBE_NODISCARD bool open() { return open(QIODevice::ReadWrite); }
0053
0054 QString fileName() const override;
0055 QString fileTemplate() const;
0056 void setFileTemplate(const QString &name);
0057 #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
0058 Q_WEAK_OVERLOAD
0059 void setFileTemplate(const std::filesystem::path &name)
0060 {
0061 return setFileTemplate(QtPrivate::fromFilesystemPath(name));
0062 }
0063 #endif
0064
0065
0066 bool rename(const QString &newName);
0067
0068 #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
0069 Q_WEAK_OVERLOAD
0070 bool rename(const std::filesystem::path &newName)
0071 {
0072 return rename(QtPrivate::fromFilesystemPath(newName));
0073 }
0074 #endif
0075
0076 inline static QTemporaryFile *createNativeFile(const QString &fileName)
0077 { QFile file(fileName); return createNativeFile(file); }
0078 static QTemporaryFile *createNativeFile(QFile &file);
0079
0080 #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
0081 Q_WEAK_OVERLOAD
0082 static QTemporaryFile *createNativeFile(const std::filesystem::path &fileName)
0083 {
0084 QFile file(fileName);
0085 return createNativeFile(file);
0086 }
0087 #endif
0088
0089 protected:
0090 bool open(OpenMode flags) override;
0091
0092 private:
0093 friend class QFile;
0094 friend class QLockFilePrivate;
0095 Q_DISABLE_COPY(QTemporaryFile)
0096 };
0097
0098 #endif
0099
0100 QT_END_NAMESPACE
0101
0102 #endif