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
4#ifndef QTEMPORARYFILE_H
5#define QTEMPORARYFILE_H
6
7#include <QtCore/qiodevice.h>
8#include <QtCore/qfile.h>
9
10#ifdef open
11#error qtemporaryfile.h must be included before any header file that defines open
12#endif
13
14QT_BEGIN_NAMESPACE
15
16
17#ifndef QT_NO_TEMPORARYFILE
18
19class QTemporaryFilePrivate;
20class QLockFilePrivate;
21
22class Q_CORE_EXPORT QTemporaryFile : public QFile
23{
24#ifndef QT_NO_QOBJECT
25 Q_OBJECT
26#endif
27 Q_DECLARE_PRIVATE(QTemporaryFile)
28
29public:
30 QTemporaryFile();
31 explicit QTemporaryFile(const QString &templateName);
32#ifndef QT_NO_QOBJECT
33 explicit QTemporaryFile(QObject *parent);
34 QTemporaryFile(const QString &templateName, QObject *parent);
35#endif
36 ~QTemporaryFile();
37
38 bool autoRemove() const;
39 void setAutoRemove(bool b);
40
41 // ### Hides open(flags)
42 bool open() { return open(flags: QIODevice::ReadWrite); }
43
44 QString fileName() const override;
45 QString fileTemplate() const;
46 void setFileTemplate(const QString &name);
47
48 // Hides QFile::rename
49 bool rename(const QString &newName);
50
51 inline static QTemporaryFile *createNativeFile(const QString &fileName)
52 { QFile file(fileName); return createNativeFile(file); }
53 static QTemporaryFile *createNativeFile(QFile &file);
54
55protected:
56 bool open(OpenMode flags) override;
57
58private:
59 friend class QFile;
60 friend class QLockFilePrivate;
61 Q_DISABLE_COPY(QTemporaryFile)
62};
63
64#endif // QT_NO_TEMPORARYFILE
65
66QT_END_NAMESPACE
67
68#endif // QTEMPORARYFILE_H
69

source code of qtbase/src/corelib/io/qtemporaryfile.h