Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
src_corelib_io_qfileinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
6 QFileInfo fi("c:/temp/foo"); => fi.absoluteFilePath() => "C:/temp/foo"
8
10#ifdef Q_OS_UNIX
11
12QFileInfo info1("/home/bob/bin/untabify");
13info1.isSymLink(); // returns true
14info1.absoluteFilePath(); // returns "/home/bob/bin/untabify"
15info1.size(); // returns 56201
16info1.symLinkTarget(); // returns "/opt/pretty++/bin/untabify"
17
18QFileInfo info2(info1.symLinkTarget());
19info2.isSymLink(); // returns false
20info2.absoluteFilePath(); // returns "/opt/pretty++/bin/untabify"
21info2.size(); // returns 56201
22
23#endif
25
26
28#ifdef Q_OS_WIN
29
30QFileInfo info1("C:\\Users\\Bob\\untabify.lnk");
31info1.isSymLink(); // returns true
32info1.absoluteFilePath(); // returns "C:/Users/Bob/untabify.lnk"
33info1.size(); // returns 63942
34info1.symLinkTarget(); // returns "C:/Pretty++/untabify"
35
36QFileInfo info2(info1.symLinkTarget());
37info2.isSymLink(); // returns false
38info2.absoluteFilePath(); // returns "C:/Pretty++/untabify"
39info2.size(); // returns 63942
40
41#endif
43
44
46QFileInfo info("/usr/bin/env");
47
48QString path = info.absolutePath(); // path = /usr/bin
49QString base = info.baseName(); // base = env
50
51info.setFile("/etc/hosts");
52
53path = info.absolutePath(); // path = /etc
54base = info.baseName(); // base = hosts
56
58QFileInfo fi("/tmp/archive.tar.gz");
59QString name = fi.fileName(); // name = "archive.tar.gz"
61
62
64QFileInfo fi("/Applications/Safari.app");
65QString bundle = fi.bundleName(); // name = "Safari"
67
68
70QFileInfo fi("/tmp/archive.tar.gz");
71QString base = fi.baseName(); // base = "archive"
73
74
76QFileInfo fi("/tmp/archive.tar.gz");
77QString base = fi.completeBaseName(); // base = "archive.tar"
79
80
82QFileInfo fi("/tmp/archive.tar.gz");
83QString ext = fi.completeSuffix(); // ext = "tar.gz"
85
86
88QFileInfo fi("/tmp/archive.tar.gz");
89QString ext = fi.suffix(); // ext = "gz"
91
92
98
99
101QFileInfo fi("/tmp/archive.tar.gz");
103 qWarning("I can change the file; my group can read the file");
105 qWarning("The group or others can change the file");
\inmodule QtCore \reentrant
Definition qfileinfo.h:22
bool isSymLink() const
Returns true if this object points to a symbolic link, shortcut, or alias; otherwise returns false.
QString baseName() const
Returns the base name of the file without the path.
QString completeSuffix() const
Returns the complete suffix (extension) of the file.
QString symLinkTarget() const
QString suffix() const
Returns the suffix (extension) of the file.
QString fileName() const
Returns the name of the file, excluding the path.
QString bundleName() const
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
QString absoluteFilePath() const
Returns an absolute path including the file name.
QString completeBaseName() const
Returns the complete base name of the file without the path.
QString absolutePath() const
Returns a file's path absolute path.
bool permission(QFile::Permissions permissions) const
Tests for file permissions.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
#define qWarning
Definition qlogging.h:162
GLuint name
GLsizei const GLchar *const * path
QString bundle
QFileInfo info(fileName)
[8]
QFileInfo fi("c:/temp/foo")
[newstuff]