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
qsavefile.h
Go to the documentation of this file.
1// Copyright (C) 2012 David Faure <faure@kde.org>
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:header-decls-only
4
5#ifndef QSAVEFILE_H
6#define QSAVEFILE_H
7
8#include <QtCore/qglobal.h>
9
10#if QT_CONFIG(temporaryfile)
11
12#include <QtCore/qfiledevice.h>
13#include <QtCore/qstring.h>
14
15#ifdef open
16#error qsavefile.h must be included before any header file that defines open
17#endif
18
19QT_BEGIN_NAMESPACE
20
21class QAbstractFileEngine;
22class QSaveFilePrivate;
23
24class Q_CORE_EXPORT QSaveFile : public QFileDevice
25{
26 Q_OBJECT
27 Q_DECLARE_PRIVATE(QSaveFile)
28
29public:
30#if QT_CORE_REMOVED_SINCE(6, 11)
31 explicit QSaveFile(const QString &name);
32#endif
33 explicit QSaveFile(QObject *parent = nullptr);
34 explicit QSaveFile(const QString &name, QObject *parent = nullptr);
35 ~QSaveFile();
36
37 QString fileName() const override;
38 void setFileName(const QString &name);
39
40 QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override;
41 bool commit();
42
43 void cancelWriting();
44
45 void setDirectWriteFallback(bool enabled);
46 bool directWriteFallback() const;
47
48#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
49 Q_WEAK_OVERLOAD QSaveFile(const std::filesystem::path &path, QObject *parent = nullptr)
50 : QSaveFile(QtPrivate::fromFilesystemPath(path), parent)
51 {
52 }
53
54 std::filesystem::path filesystemFileName() const
55 { return QtPrivate::toFilesystemPath(fileName()); }
56 Q_WEAK_OVERLOAD void setFileName(const std::filesystem::path &name)
57 {
58 setFileName(QtPrivate::fromFilesystemPath(name));
59 }
60#endif // QT_CONFIG(cxx17_filesystem)
61
62protected:
63 qint64 writeData(const char *data, qint64 len) override;
64
65private:
66 void close() override;
67#if !QT_CONFIG(translation)
68 static QString tr(const char *string) { return QString::fromLatin1(string); }
69#endif
70
71private:
72 Q_DISABLE_COPY(QSaveFile)
73 friend class QFilePrivate;
74};
75
76QT_END_NAMESPACE
77
78#endif // QT_CONFIG(temporaryfile)
79
80#endif // QSAVEFILE_H
Combined button and popup list for selecting options.
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