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
qfileinfo.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 QFILEINFO_H
6#define QFILEINFO_H
7
8#include <QtCore/qcompare.h>
9#include <QtCore/qfile.h>
10#include <QtCore/qlist.h>
11#include <QtCore/qshareddata.h>
12#include <QtCore/qmetatype.h>
13#include <QtCore/qdatetime.h>
14#include <QtCore/qtimezone.h>
15
17
18
19class QDir;
21
23QT_DECLARE_QSDP_SPECIALIZATION_DTOR(QFileInfoPrivate)
24
25class Q_CORE_EXPORT QFileInfo
26{
27 friend class QDirIteratorPrivate;
28 friend class QDirListingPrivate;
29 friend class QFileInfoPrivate;
30public:
31 explicit QFileInfo(QFileInfoPrivate *d);
32
33#ifdef QT_IMPLICIT_QFILEINFO_CONSTRUCTION
34#define QFILEINFO_MAYBE_EXPLICIT Q_IMPLICIT
35#else
36#define QFILEINFO_MAYBE_EXPLICIT explicit
37#endif
38
39 QFileInfo();
40 QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QString &file);
41 QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QFileDevice &file);
42 QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QDir &dir, const QString &file);
43 QFileInfo(const QFileInfo &fileinfo);
44 QFileInfo(QFileInfo &&other) = default;
45#ifdef Q_QDOC
46 QFileInfo(const std::filesystem::path &file);
47 QFileInfo(const QDir &dir, const std::filesystem::path &file);
48#elif QT_CONFIG(cxx17_filesystem)
49 template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
50 QFILEINFO_MAYBE_EXPLICIT QFileInfo(const T &file) : QFileInfo(QtPrivate::fromFilesystemPath(file)) { }
51
52 template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
53 QFILEINFO_MAYBE_EXPLICIT QFileInfo(const QDir &dir, const T &file) : QFileInfo(dir, QtPrivate::fromFilesystemPath(file))
54 {
55 }
56#endif // QT_CONFIG(cxx17_filesystem)
57
58#undef QFILEINFO_MAYBE_EXPLICIT
59
60 ~QFileInfo();
61
62 QFileInfo &operator=(const QFileInfo &fileinfo);
63 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFileInfo)
64
65 void swap(QFileInfo &other) noexcept
66 { d_ptr.swap(other.d_ptr); }
67
68#if QT_CORE_REMOVED_SINCE(6, 8)
69 bool operator==(const QFileInfo &fileinfo) const;
70 inline bool operator!=(const QFileInfo &fileinfo) const { return !(operator==(fileinfo)); }
71#endif
72
73 void setFile(const QString &file);
74 void setFile(const QFileDevice &file);
75 void setFile(const QDir &dir, const QString &file);
76#ifdef Q_QDOC
77 void setFile(const std::filesystem::path &file);
78#elif QT_CONFIG(cxx17_filesystem)
79 template<typename T, QtPrivate::ForceFilesystemPath<T> = 0>
80 void setFile(const T &file) { setFile(QtPrivate::fromFilesystemPath(file)); }
81#endif // QT_CONFIG(cxx17_filesystem)
82
83 bool exists() const;
84 static bool exists(const QString &file);
85 void refresh();
86
87 QString filePath() const;
88 QString absoluteFilePath() const;
89 QString canonicalFilePath() const;
90#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
91 std::filesystem::path filesystemFilePath() const
92 { return QtPrivate::toFilesystemPath(filePath()); }
93 std::filesystem::path filesystemAbsoluteFilePath() const
94 { return QtPrivate::toFilesystemPath(absoluteFilePath()); }
95 std::filesystem::path filesystemCanonicalFilePath() const
96 { return QtPrivate::toFilesystemPath(canonicalFilePath()); }
97#endif // QT_CONFIG(cxx17_filesystem)
98 QString fileName() const;
99 QString baseName() const;
100 QString completeBaseName() const;
101 QString suffix() const;
102 QString bundleName() const;
103 QString completeSuffix() const;
104
105 QString path() const;
106 QString absolutePath() const;
107 QString canonicalPath() const;
108#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
109 std::filesystem::path filesystemPath() const { return QtPrivate::toFilesystemPath(path()); }
110 std::filesystem::path filesystemAbsolutePath() const
111 { return QtPrivate::toFilesystemPath(absolutePath()); }
112 std::filesystem::path filesystemCanonicalPath() const
113 { return QtPrivate::toFilesystemPath(canonicalPath()); }
114#endif // QT_CONFIG(cxx17_filesystem)
115 QDir dir() const;
116 QDir absoluteDir() const;
117
118 bool isReadable() const;
119 bool isWritable() const;
120 bool isExecutable() const;
121 bool isHidden() const;
122 bool isNativePath() const;
123
124 bool isRelative() const;
125 inline bool isAbsolute() const { return !isRelative(); }
126 bool makeAbsolute();
127
128 bool isFile() const;
129 bool isDir() const;
130 bool isSymLink() const;
131 bool isSymbolicLink() const;
132 bool isOther() const;
133 bool isShortcut() const;
134 bool isAlias() const;
135 bool isJunction() const;
136 bool isRoot() const;
137 bool isBundle() const;
138
139 QString symLinkTarget() const;
140 QString readSymLink() const;
141 QString junctionTarget() const;
142
143#if QT_CONFIG(cxx17_filesystem) || defined(Q_QDOC)
144 std::filesystem::path filesystemSymLinkTarget() const
145 { return QtPrivate::toFilesystemPath(symLinkTarget()); }
146
147 std::filesystem::path filesystemReadSymLink() const
148 { return QtPrivate::toFilesystemPath(readSymLink()); }
149
150 std::filesystem::path filesystemJunctionTarget() const
151 { return QtPrivate::toFilesystemPath(junctionTarget()); }
152#endif // QT_CONFIG(cxx17_filesystem)
153
154 QString owner() const;
155 uint ownerId() const;
156 QString group() const;
157 uint groupId() const;
158
159 bool permission(QFile::Permissions permissions) const;
160 QFile::Permissions permissions() const;
161
162 qint64 size() const;
163
164 QDateTime birthTime() const { return fileTime(QFile::FileBirthTime); }
165 QDateTime metadataChangeTime() const { return fileTime(QFile::FileMetadataChangeTime); }
166 QDateTime lastModified() const { return fileTime(QFile::FileModificationTime); }
167 QDateTime lastRead() const { return fileTime(QFile::FileAccessTime); }
168 QDateTime fileTime(QFile::FileTime time) const;
169
170 QDateTime birthTime(const QTimeZone &tz) const { return fileTime(QFile::FileBirthTime, tz); }
171 QDateTime metadataChangeTime(const QTimeZone &tz) const { return fileTime(QFile::FileMetadataChangeTime, tz); }
172 QDateTime lastModified(const QTimeZone &tz) const { return fileTime(QFile::FileModificationTime, tz); }
173 QDateTime lastRead(const QTimeZone &tz) const { return fileTime(QFile::FileAccessTime, tz); }
174 QDateTime fileTime(QFile::FileTime time, const QTimeZone &tz) const;
175
176 bool caching() const;
177 void setCaching(bool on);
178 void stat();
179
180protected:
181 QSharedDataPointer<QFileInfoPrivate> d_ptr;
182
183private:
184 friend Q_CORE_EXPORT bool comparesEqual(const QFileInfo &lhs, const QFileInfo &rhs);
185 Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QFileInfo)
186 QFileInfoPrivate* d_func();
187 inline const QFileInfoPrivate* d_func() const
188 {
189 return d_ptr.constData();
190 }
191};
192
194
196
197#ifndef QT_NO_DEBUG_STREAM
198Q_CORE_EXPORT QDebug operator<<(QDebug, const QFileInfo &);
199#endif
200
201QT_END_NAMESPACE
202
203QT_DECL_METATYPE_EXTERN(QFileInfo, Q_CORE_EXPORT)
204
205#endif // QFILEINFO_H
Combined button and popup list for selecting options.
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2618
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:36
QList< QFileInfo > QFileInfoList
Definition qfileinfo.h:195