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