Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-05 09:27:48

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
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 // QT_CONFIG(cxx17_filesystem)
0044 #endif // !QT_NO_QOBJECT
0045 
0046     ~QTemporaryFile();
0047 
0048     bool autoRemove() const;
0049     void setAutoRemove(bool b);
0050 
0051     // ### Hides open(flags)
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 // QT_CONFIG(cxx17_filesystem)
0064 
0065     // Hides QFile::rename
0066     bool rename(const QString &newName);
0067     bool renameOverwrite(const QString &newName);
0068 
0069 #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
0070     Q_WEAK_OVERLOAD
0071     bool rename(const std::filesystem::path &newName)
0072     {
0073         return rename(QtPrivate::fromFilesystemPath(newName));
0074     }
0075     Q_WEAK_OVERLOAD
0076     bool renameOverwrite(const std::filesystem::path &newName)
0077     { return renameOverwrite(QtPrivate::fromFilesystemPath(newName)); }
0078 #endif // QT_CONFIG(cxx17_filesystem)
0079 
0080     inline static QTemporaryFile *createNativeFile(const QString &fileName)
0081         { QFile file(fileName); return createNativeFile(file); }
0082     static QTemporaryFile *createNativeFile(QFile &file);
0083 
0084 #if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
0085     Q_WEAK_OVERLOAD
0086     static QTemporaryFile *createNativeFile(const std::filesystem::path &fileName)
0087     {
0088         QFile file(fileName);
0089         return createNativeFile(file);
0090     }
0091 #endif // QT_CONFIG(cxx17_filesystem)
0092 
0093 protected:
0094     bool open(OpenMode flags) override;
0095 
0096 private:
0097     friend class QFile;
0098     friend class QLockFilePrivate;
0099     Q_DISABLE_COPY(QTemporaryFile)
0100 };
0101 
0102 #endif // QT_CONFIG(temporaryfile)
0103 
0104 QT_END_NAMESPACE
0105 
0106 #endif // QTEMPORARYFILE_H