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