Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtemporaryfile.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QTEMPORARYFILE_H
6#define QTEMPORARYFILE_H
7
8#include <QtCore/qiodevice.h>
9#include <QtCore/qfile.h>
10
11#ifdef open
12#error qtemporaryfile.h must be included before any header file that defines open
13#endif
14
16
17
18#if QT_CONFIG(temporaryfile)
19
20class QTemporaryFilePrivate;
21class QLockFilePrivate;
22
23class Q_CORE_EXPORT QTemporaryFile : public QFile
24{
25#ifndef QT_NO_QOBJECT
26 Q_OBJECT
27#endif
28 Q_DECLARE_PRIVATE(QTemporaryFile)
29
30public:
31 QTemporaryFile();
32 explicit QTemporaryFile(const QString &templateName);
33#ifndef QT_NO_QOBJECT
34 explicit QTemporaryFile(QObject *parent);
35 QTemporaryFile(const QString &templateName, QObject *parent);
36
37# if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
38 Q_WEAK_OVERLOAD
39 explicit QTemporaryFile(const std::filesystem::path &templateName, QObject *parent = nullptr)
40 : QTemporaryFile(QtPrivate::fromFilesystemPath(templateName), parent)
41 {
42 }
43# endif // QT_CONFIG(cxx17_filesystem)
44#endif // !QT_NO_QOBJECT
45
46 ~QTemporaryFile();
47
48 bool autoRemove() const;
49 void setAutoRemove(bool b);
50
51 // ### Hides open(flags)
52 QFILE_MAYBE_NODISCARD bool open() { return open(QIODevice::ReadWrite); }
53
54 QString fileName() const override;
55 QString fileTemplate() const;
56 void setFileTemplate(const QString &name);
57#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
58 Q_WEAK_OVERLOAD
59 void setFileTemplate(const std::filesystem::path &name)
60 {
61 return setFileTemplate(QtPrivate::fromFilesystemPath(name));
62 }
63#endif // QT_CONFIG(cxx17_filesystem)
64
65 // Hides QFile::rename
66 bool rename(const QString &newName);
67 bool renameOverwrite(const QString &newName);
68
69#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
70 Q_WEAK_OVERLOAD
71 bool rename(const std::filesystem::path &newName)
72 {
73 return rename(QtPrivate::fromFilesystemPath(newName));
74 }
75 Q_WEAK_OVERLOAD
76 bool renameOverwrite(const std::filesystem::path &newName)
77 { return renameOverwrite(QtPrivate::fromFilesystemPath(newName)); }
78#endif // QT_CONFIG(cxx17_filesystem)
79
80 inline static QTemporaryFile *createNativeFile(const QString &fileName)
81 { QFile file(fileName); return createNativeFile(file); }
82 static QTemporaryFile *createNativeFile(QFile &file);
83
84#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
85 Q_WEAK_OVERLOAD
86 static QTemporaryFile *createNativeFile(const std::filesystem::path &fileName)
87 {
88 QFile file(fileName);
89 return createNativeFile(file);
90 }
91#endif // QT_CONFIG(cxx17_filesystem)
92
93protected:
94 bool open(OpenMode flags) override;
95
96private:
97 friend class QFile;
98 friend class QLockFilePrivate;
99 Q_DISABLE_COPY(QTemporaryFile)
100};
101
102#endif // QT_CONFIG(temporaryfile)
103
104QT_END_NAMESPACE
105
106#endif // QTEMPORARYFILE_H
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2568
static Q_DECL_COLD_FUNCTION bool file_already_open(QFile &file, const char *where=nullptr)
Definition qfile.cpp:33
#define QFILEINFO_MAYBE_EXPLICIT
Definition qfileinfo.h:34
QList< QFileInfo > QFileInfoList
Definition qfileinfo.h:192