IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QFileInfo Class

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QFileInfo Class▲

  • Header: QFileInfo

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

  • Group: QFileInfo is part of https://, https://

Detailed Description▲

https:// provides information about a file's name and position (path) in the file system, its access rights and whether it is a directory or symbolic link, etc. The file's size and last modified/read times are also available. https:// can also be used to obtain information about a Qt https://.

A https:// can point to a file with either a relative or an absolute file path. Absolute file paths begin with the directory separator "/" (or with a drive specification on Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current working directory. An example of an absolute path is the string "/tmp/quartz". A relative path might look like "src/fatlib". You can use the function https://() to check whether a https:// is using a relative or an absolute file path. You can call the function https://() to convert a relative https://'s path to an absolute path.

Paths starting with a colon (:) are always considered absolute, as they denote a https://.

The file that the https:// works on is set in the constructor or later with https://(). Use https://() to see if the file exists and https://() to get its size.

The file's type is obtained with https://(), https://() and https://(). The https://() function provides the name of the file the symlink points to.

On Unix (including macOS and iOS), the property getter functions in this class return the properties such as times and size of the target file, not the symlink, because Unix handles symlinks transparently. Opening a symlink using https:// effectively opens the link's target. For example:

 
Sélectionnez
#ifdef Q_OS_UNIX

QFileInfo info1("/home/bob/bin/untabify");
info1.isSymLink();          // returns true
info1.absoluteFilePath();   // returns "/home/bob/bin/untabify"
info1.size();               // returns 56201
info1.symLinkTarget();      // returns "/opt/pretty++/bin/untabify"

QFileInfo info2(info1.symLinkTarget());
info2.isSymLink();          // returns false
info2.absoluteFilePath();   // returns "/opt/pretty++/bin/untabify"
info2.size();               // returns 56201

#endif

On Windows, shortcuts (.lnk files) are currently treated as symlinks. As on Unix systems, the property getters return the size of the targeted file, not the .lnk file itself. This behavior is deprecated and will likely be removed in a future version of Qt, after which .lnk files will be treated as regular files.

 
Sélectionnez
#ifdef Q_OS_WIN

QFileInfo info1("C:\\Users\\Bob\\untabify.lnk");
info1.isSymLink();          // returns true
info1.absoluteFilePath();   // returns "C:/Users/Bob/untabify.lnk"
info1.size();               // returns 63942
info1.symLinkTarget();      // returns "C:/Pretty++/untabify"

QFileInfo info2(info1.symLinkTarget());
info2.isSymLink();          // returns false
info2.absoluteFilePath();   // returns "C:/Pretty++/untabify"
info2.size();               // returns 63942

#endif

Elements of the file's name can be extracted with https://() and https://(). The https://()'s parts can be extracted with https://(), https://() or https://(). https:// objects to directories created by Qt classes will not have a trailing file separator. If you wish to use trailing separators in your own file info objects, just append one to the file name given to the constructors or https://().

The file's dates are returned by https://(), https://(), https://() and https://(). Information about the file's access permissions is obtained with https://(), https://() and https://(). The file's ownership is available from https://(), https://(), https://() and https://(). You can examine a file's permissions and ownership in a single statement using the https://() function.

On NTFS file systems, ownership and permissions checking is disabled by default for performance reasons. To enable it, include the following line:

 
Sélectionnez
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;

Permission checking is then turned on and off by incrementing and decrementing qt_ntfs_permission_lookup by 1.

 
Sélectionnez
qt_ntfs_permission_lookup++; // turn checking on
qt_ntfs_permission_lookup--; // turn it off again

Since this is a non-atomic global variable, it is only safe to increment or decrement qt_ntfs_permission_lookup before any threads other than the main thread have started or after every thread other than the main thread has ended.

Performance Issues▲

Some of https://'s functions query the file system, but for performance reasons, some functions only operate on the file name itself. For example: To return the absolute path of a relative file name, https://() has to query the file system. The https://() function, however, can work on the file name directly, and so it is faster.

To speed up performance, https:// caches information about the file.

Because files can be changed by other users or programs, or even by other parts of the same program, there is a function that refreshes the file information: https://(). If you want to switch off a https://'s caching and force it to access the file system every time you request information from it call https://(false). If you want to make sure that all information is read from the file system, use https://().

Platform Specific Issues▲

On Android, some limitations apply when dealing with https://:

  • Access permissions might be needed by prompting the user through the https:// which implements Android's native file picker.

  • Aim to follow the https:// guidelines, such as using app specific directories instead of other public external directories. For more information, also see https://.

  • Due to the design of Qt APIs (e.g. https://), it's not possible to fully integrate the latter APIs with Android's https:// APIs.

See Also▲

See also https://, https://

Member Function Documentation▲

 

QFileInfo::QFileInfo()▲

Constructs an empty https:// object.

Note that an empty https:// object contain no file reference.

See Also▲

See also https://()

[explicit] QFileInfo::QFileInfo(const QString &file)▲

Constructs a new https:// that gives information about the given file. The file can also include an absolute or relative path.

See Also▲

See also https://(), https://(), https://(), https://()

[explicit] QFileInfo::QFileInfo(const QFileDevice &file)▲

Constructs a new https:// that gives information about file file.

If the file has a relative path, the https:// will also have a relative path.

See Also▲

See also https://()

[explicit] QFileInfo::QFileInfo(const QDir &dir, const QString &file)▲

Constructs a new https:// that gives information about the given file relative to the directory dir.

If dir has a relative path, the https:// will also have a relative path.

If file is an absolute path, then the directory specified by dir will be disregarded.

See Also▲

See also https://()

[since 6.0] QFileInfo::QFileInfo(const std::filesystem::path &file)▲

Constructs a new https:// that gives information about the given file.

This function was introduced in Qt 6.0.

See Also▲

See also https://(), https://(), https://(), https://()

[since 6.0] QFileInfo::QFileInfo(const QDir &dir, const std::filesystem::path &file)▲

Constructs a new https:// that gives information about the given file relative to the directory dir.

If dir has a relative path, the https:// will also have a relative path.

If file is an absolute path, then the directory specified by dir will be disregarded.

This function was introduced in Qt 6.0.

QFileInfo::QFileInfo(const QFileInfo &fileinfo)▲

Constructs a new https:// that is a copy of the given fileinfo.

QFileInfo::~QFileInfo()▲

Destroys the https:// and frees its resources.

QDir QFileInfo::absoluteDir() const▲

Returns the file's absolute path as a https:// object.

See Also▲

See also https://(), https://(), https://(), https://()

QString QFileInfo::absoluteFilePath() const▲

Returns an absolute path including the file name.

The absolute path name consists of the full path and the file name. On Unix this will always begin with the root, '/', directory. On Windows this will always begin 'D:/' where D is a drive letter, except for network shares that are not mapped to a drive letter, in which case the path will begin '//sharename/'. https:// will uppercase drive letters. Note that https:// does not do this. The code snippet below shows this.

 
Sélectionnez
    QFileInfo fi("c:/temp/foo"); => fi.absoluteFilePath() => "C:/temp/foo"

This function returns the same as https://(), unless https://() is true. In contrast to https://(), symbolic links or redundant "." or ".." elements are not necessarily removed.

If https://() is empty the behavior of this function is undefined.

See Also▲

See also https://(), https://(), https://()

QString QFileInfo::absolutePath() const▲

Returns a file's path absolute path. This doesn't include the file name.

On Unix the absolute path will always begin with the root, '/', directory. On Windows this will always begin 'D:/' where D is a drive letter, except for network shares that are not mapped to a drive letter, in which case the path will begin '//sharename/'.

In contrast to https://() symbolic links or redundant "." or ".." elements are not necessarily removed.

If https://() is empty the behavior of this function is undefined.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QString QFileInfo::baseName() const▲

Returns the base name of the file without the path.

The base name consists of all characters in the file up to (but not including) the first '.' character.

Example:

 
Sélectionnez
QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.baseName();  // base = "archive"

The base name of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc").

See Also▲

See also https://(), https://(), https://(), https://()

QDateTime QFileInfo::birthTime() const▲

Returns the date and time when the file was created / born.

If the file birth time is not available, this function returns an invalid https://.

If the file is a symlink, the time of the target file is returned (not the symlink).

See Also▲

See also https://(), https://(), https://()

QString QFileInfo::bundleName() const▲

Returns the name of the bundle.

On macOS and iOS this returns the proper localized name for a bundle if the path https://(). On all other platforms an empty https:// is returned.

Example:

 
Sélectionnez
QFileInfo fi("/Applications/Safari.app");
QString bundle = fi.bundleName();                // name = "Safari"
See Also▲

See also https://(), https://(), https://(), https://()

bool QFileInfo::caching() const▲

Returns true if caching is enabled; otherwise returns false.

See Also▲

See also https://(), https://()

QString QFileInfo::canonicalFilePath() const▲

Returns the canonical path including the file name, i.e. an absolute path without symbolic links or redundant "." or ".." elements.

If the file does not exist, canonicalFilePath() returns an empty string.

See Also▲

See also https://(), https://(), https://()

QString QFileInfo::canonicalPath() const▲

Returns the file's path canonical path (excluding the file name), i.e. an absolute path without symbolic links or redundant "." or ".." elements.

If the file does not exist, canonicalPath() returns an empty string.

See Also▲

See also https://(), https://()

QString QFileInfo::completeBaseName() const▲

Returns the complete base name of the file without the path.

The complete base name consists of all characters in the file up to (but not including) the last '.' character.

Example:

 
Sélectionnez
QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.completeBaseName();  // base = "archive.tar"
See Also▲

See also https://(), https://(), https://(), https://()

QString QFileInfo::completeSuffix() const▲

Returns the complete suffix (extension) of the file.

The complete suffix consists of all characters in the file after (but not including) the first '.'.

Example:

 
Sélectionnez
QFileInfo fi("/tmp/archive.tar.gz");
QString ext = fi.completeSuffix();  // ext = "tar.gz"
See Also▲

See also https://(), https://(), https://(), https://()

QDir QFileInfo::dir() const▲

Returns the path of the object's parent directory as a https:// object.

Note: The https:// returned always corresponds to the object's parent directory, even if the https:// represents a directory.

For each of the following, dir() returns the https:// "~/examples/191697".

 
Sélectionnez
    QFileInfo fileInfo1("~/examples/191697/.");
    QFileInfo fileInfo2("~/examples/191697/..");
    QFileInfo fileInfo3("~/examples/191697/main.cpp");

For each of the following, dir() returns the https:// ".".

 
Sélectionnez
    QFileInfo fileInfo4(".");
    QFileInfo fileInfo5("..");
    QFileInfo fileInfo6("main.cpp");
See Also▲

See also https://(), https://(), https://(), https://(), https://()

bool QFileInfo::exists() const▲

Returns true if the file exists; otherwise returns false.

If the file is a symlink that points to a non-existing file, false is returned.

[static] bool QFileInfo::exists(const QString &file)▲

Returns true if the file exists; otherwise returns false.

If file is a symlink that points to a non-existing file, false is returned.

Using this function is faster than using QFileInfo(file).exists() for file system access.

QString QFileInfo::fileName() const▲

Returns the name of the file, excluding the path.

Example:

 
Sélectionnez
QFileInfo fi("/tmp/archive.tar.gz");
QString name = fi.fileName();                // name = "archive.tar.gz"

Note that, if this https:// object is given a path ending in a slash, the name of the file is considered empty.

See Also▲

See also https://(), https://(), https://(), https://()

QString QFileInfo::filePath() const▲

Returns the file name, including the path (which may be absolute or relative).

See Also▲

See also https://(), https://(), https://()

QDateTime QFileInfo::fileTime(QFile::FileTime time) const▲

Returns the file time specified by time. If the time cannot be determined, an invalid date time is returned.

If the file is a symlink, the time of the target file is returned (not the symlink).

See Also▲

See also https://, https://()

[since 6.0] std::filesystem::path QFileInfo::filesystemAbsoluteFilePath() const▲

Returns https://() as a std::filesystem::path.

This function was introduced in Qt 6.0.

See Also▲

See also https://()

[since 6.0] std::filesystem::path QFileInfo::filesystemAbsolutePath() const▲

Returns https://() as a std::filesystem::path.

This function was introduced in Qt 6.0.

See Also▲

See also https://()

[since 6.0] std::filesystem::path QFileInfo::filesystemCanonicalFilePath() const▲

Returns https://() as a std::filesystem::path.

This function was introduced in Qt 6.0.

See Also▲

See also https://()

[since 6.0] std::filesystem::path QFileInfo::filesystemCanonicalPath() const▲

Returns https://() as a std::filesystem::path.

This function was introduced in Qt 6.0.

See Also▲

See also https://()

[since 6.0] std::filesystem::path QFileInfo::filesystemFilePath() const▲

Returns https://() as a std::filesystem::path.

This function was introduced in Qt 6.0.

See Also▲

See also https://()

[since 6.2] std::filesystem::path QFileInfo::filesystemJunctionTarget() const▲

Returns https://() as a std::filesystem::path.

This function was introduced in Qt 6.2.

See Also▲

See also https://()

[since 6.0] std::filesystem::path QFileInfo::filesystemPath() const▲

Returns https://() as a std::filesystem::path.

This function was introduced in Qt 6.0.

See Also▲

See also https://()

[since 6.0] std::filesystem::path QFileInfo::filesystemSymLinkTarget() const▲

Returns https://() as a std::filesystem::path.

This function was introduced in Qt 6.0.

See Also▲

See also https://()

QString QFileInfo::group() const▲

Returns the group of the file. On Windows, on systems where files do not have groups, or if an error occurs, an empty string is returned.

This function can be time consuming under Unix (in the order of milliseconds).

If the file is a symlink, this function returns the owning group of the target (not the symlink).

See Also▲

See also https://(), https://(), https://()

uint QFileInfo::groupId() const▲

Returns the id of the group the file belongs to.

On Windows and on systems where files do not have groups this function always returns (uint) -2.

If the file is a symlink, this function returns the id of the group owning the target (not the symlink).

See Also▲

See also https://(), https://(), https://()

bool QFileInfo::isAbsolute() const▲

Returns true if the file path is absolute, otherwise returns false (i.e. the path is relative).

Paths starting with a colon (:) are always considered absolute, as they denote a https://.

See Also▲

See also https://()

[since 6.4] bool QFileInfo::isAlias() const▲

Returns true if this object points to an alias; otherwise returns false.

Aliases only exist on macOS. They are treated as regular files, so opening an alias will open the file itself. In order to open the file or directory an alias references use https://().

Even if an alias points to a non existing file, isAlias() returns true.

This function was introduced in Qt 6.4.

See Also▲

See also https://(), https://(), https://(), https://()

bool QFileInfo::isBundle() const▲

Returns true if this object points to a bundle or to a symbolic link to a bundle on macOS and iOS; otherwise returns false.

If the file is a symlink, this function returns true if the target is a bundle (not the symlink).

See Also▲

See also https://(), https://(), https://()

bool QFileInfo::isDir() const▲

Returns true if this object points to a directory or to a symbolic link to a directory; otherwise returns false.

If the file is a symlink, this function returns true if the target is a directory (not the symlink).

See Also▲

See also https://(), https://(), https://()

bool QFileInfo::isExecutable() const▲

Returns true if the file is executable; otherwise returns false.

If the file is a symlink, this function returns true if the target is executable (not the symlink).

See Also▲

See also https://(), https://(), https://()

bool QFileInfo::isFile() const▲

Returns true if this object points to a file or to a symbolic link to a file. Returns false if the object points to something which isn't a file, such as a directory.

If the file is a symlink, this function returns true if the target is a regular file (not the symlink).

See Also▲

See also https://(), https://(), https://()

bool QFileInfo::isHidden() const▲

Returns true if this is a `hidden' file; otherwise returns false.

Note: This function returns true for the special entries "." and ".." on Unix, even though https:// threats them as shown. And note that, since this function inspects the file name, on Unix it will inspect the name of the symlink, if this file is a symlink, not the target's name.

On Windows, this function returns true if the target file is hidden (not the symlink).

bool QFileInfo::isJunction() const▲

Returns true if the object points to a junction; otherwise returns false.

Junctions only exist on Windows' NTFS file system, and are typically created by the mklink command. They can be thought of as symlinks for directories, and can only be created for absolute paths on the local volume.

bool QFileInfo::isNativePath() const▲

Returns true if the file path can be used directly with native APIs. Returns false if the file is otherwise supported by a virtual file system inside Qt, such as https://.

Note: Native paths may still require conversion of path separators and character encoding, depending on platform and input requirements of the native API.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

bool QFileInfo::isReadable() const▲

Returns true if the user can read the file; otherwise returns false.

If the file is a symlink, this function returns true if the target is readable (not the symlink).

If the https:// check has not been enabled, the result on Windows will merely reflect whether the file exists.

See Also▲

See also https://(), https://(), https://()

bool QFileInfo::isRelative() const▲

Returns true if the file path is relative, otherwise returns false (i.e. the path is absolute). (E.g. under Unix a path is absolute if it begins with a "/").

Paths starting with a colon (:) are always considered absolute, as they denote a https://.

See Also▲

See also https://()

bool QFileInfo::isRoot() const▲

Returns true if the object points to a directory or to a symbolic link to a directory, and that directory is the root directory; otherwise returns false.

bool QFileInfo::isShortcut() const▲

Returns true if this object points to a shortcut; otherwise returns false.

Shortcuts only exist on Windows and are typically .lnk files. For instance, true will be returned for shortcuts (*.lnk files) on Windows, but false will be returned on Unix (including macOS and iOS).

The shortcut (.lnk) files are treated as regular files. Opening those will open the .lnk file itself. In order to open the file a shortcut references to, it must uses https://() on a shortcut.

Even if a shortcut (broken shortcut) points to a non existing file, isShortcut() returns true.

See Also▲

See also https://(), https://(), https://(), https://()

bool QFileInfo::isSymLink() const▲

Symbolic links exist on Unix (including macOS and iOS) and Windows and are typically created by the ln -s or mklink commands, respectively. Opening a symbolic link effectively opens the https://.

In addition, true will be returned for shortcuts (*.lnk files) on Windows, and aliases on macOS. This behavior is deprecated and will likely change in a future version of Qt. Opening a shortcut or alias will open the .lnk or alias file itself.

Example:

 
Sélectionnez
QFileInfo info(fileName);
if (info.isSymLink())
    fileName = info.symLinkTarget();

If the symlink points to a non existing file, https://() returns false.

See Also▲

See also https://(), https://(), https://()

bool QFileInfo::isSymbolicLink() const▲

Symbolic links exist on Unix (including macOS and iOS) and Windows (NTFS-symlink) and are typically created by the ln -s or mklink commands, respectively.

Unix handles symlinks transparently. Opening a symbolic link effectively opens the https://.

In contrast to https://(), false will be returned for shortcuts (*.lnk files) on Windows and aliases on macOS. Use https://() and https://() instead.

If the symlink points to a non existing file, https://() returns false.

See Also▲

See also https://(), https://(), https://(), https://()

bool QFileInfo::isWritable() const▲

Returns true if the user can write to the file; otherwise returns false.

If the file is a symlink, this function returns true if the target is writeable (not the symlink).

If the https:// check has not been enabled, the result on Windows will merely reflect whether the file is marked as Read Only.

See Also▲

See also https://(), https://(), https://()

[since 6.2] QString QFileInfo::junctionTarget() const▲

Resolves an NTFS junction to the path it references.

Returns the absolute path to the directory an NTFS junction points to, or an empty string if the object is not an NTFS junction.

There is no guarantee that the directory named by the NTFS junction actually exists.

This function was introduced in Qt 6.2.

See Also▲

See also https://(), https://(), https://(), https://(), https://(), https://()

QDateTime QFileInfo::lastModified() const▲

Returns the date and local time when the file was last modified.

If the file is a symlink, the time of the target file is returned (not the symlink).

See Also▲

See also https://(), https://(), https://(), https://()

QDateTime QFileInfo::lastRead() const▲

Returns the date and local time when the file was last read (accessed).

On platforms where this information is not available, returns the same as https://().

If the file is a symlink, the time of the target file is returned (not the symlink).

See Also▲

See also https://(), https://(), https://(), https://()

bool QFileInfo::makeAbsolute()▲

Converts the file's path to an absolute path if it is not already in that form. Returns true to indicate that the path was converted; otherwise returns false to indicate that the path was already absolute.

See Also▲

See also https://(), https://()

QDateTime QFileInfo::metadataChangeTime() const▲

Returns the date and time when the file metadata was changed. A metadata change occurs when the file is created, but it also occurs whenever the user writes or sets inode information (for example, changing the file permissions).

If the file is a symlink, the time of the target file is returned (not the symlink).

See Also▲

See also https://(), https://()

QString QFileInfo::owner() const▲

Returns the owner of the file. On systems where files do not have owners, or if an error occurs, an empty string is returned.

This function can be time consuming under Unix (in the order of milliseconds). On Windows, it will return an empty string unless the https:// check has been enabled.

If the file is a symlink, this function returns the owner of the target (not the symlink).

See Also▲

See also https://(), https://(), https://()

uint QFileInfo::ownerId() const▲

Returns the id of the owner of the file.

On Windows and on systems where files do not have owners this function returns ((uint) -2).

If the file is a symlink, this function returns the id of the owner of the target (not the symlink).

See Also▲

See also https://(), https://(), https://()

QString QFileInfo::path() const▲

Returns the file's path. This doesn't include the file name.

Note that, if this https:// object is given a path ending in a slash, the name of the file is considered empty and this function will return the entire path.

See Also▲

See also https://(), https://(), https://(), https://(), https://(), https://()

bool QFileInfo::permission(QFile::Permissions permissions) const▲

Tests for file permissions. The permissions argument can be several flags of type QFile::Permissions OR-ed together to check for permission combinations.

On systems where files do not have permissions this function always returns true.

The result might be inaccurate on Windows if the https:// check has not been enabled.

Example:

 
Sélectionnez
QFileInfo fi("/tmp/archive.tar.gz");
if (fi.permission(QFile::WriteUser | QFile::ReadGroup))
    qWarning("I can change the file; my group can read the file");
if (fi.permission(QFile::WriteGroup | QFile::WriteOther))
    qWarning("The group or others can change the file");

If the file is a symlink, this function checks the permissions of the target (not the symlink).

See Also▲

See also https://(), https://(), https://()

QFile::Permissions QFileInfo::permissions() const▲

Returns the complete OR-ed together combination of QFile::Permissions for the file.

The result might be inaccurate on Windows if the https:// check has not been enabled.

If the file is a symlink, this function returns the permissions of the target (not the symlink).

void QFileInfo::refresh()▲

Refreshes the information about the file, i.e. reads in information from the file system the next time a cached property is fetched.

void QFileInfo::setCaching(bool enable)▲

If enable is true, enables caching of file information. If enable is false caching is disabled.

When caching is enabled, https:// reads the file information from the file system the first time it's needed, but generally not later.

Caching is enabled by default.

See Also▲

See also https://(), https://()

void QFileInfo::setFile(const QString &file)▲

Sets the file that the https:// provides information about to file.

The file can also include an absolute or relative file path. Absolute paths begin with the directory separator (e.g. "/" under Unix) or a drive specification (under Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current directory.

Example:

 
Sélectionnez
QFileInfo info("/usr/bin/env");

QString path = info.absolutePath(); // path = /usr/bin
QString base = info.baseName(); // base = env

info.setFile("/etc/hosts");

path = info.absolutePath(); // path = /etc
base = info.baseName(); // base = hosts
See Also▲

See also https://(), https://(), https://(), https://()

void QFileInfo::setFile(const QFileDevice &file)▲

This is an overloaded function.

Sets the file that the https:// provides information about to file.

If file includes a relative path, the https:// will also have a relative path.

See Also▲

See also https://()

void QFileInfo::setFile(const QDir &dir, const QString &file)▲

This is an overloaded function.

Sets the file that the https:// provides information about to file in directory dir.

If file includes a relative path, the https:// will also have a relative path.

See Also▲

See also https://()

[since 6.0] void QFileInfo::setFile(const std::filesystem::path &file)▲

Sets the file that the https:// provides information about to file.

This function was introduced in Qt 6.0.

qint64 QFileInfo::size() const▲

Returns the file size in bytes. If the file does not exist or cannot be fetched, 0 is returned.

If the file is a symlink, the size of the target file is returned (not the symlink).

See Also▲

See also https://()

[since 6.0] void QFileInfo::stat()▲

Reads all attributes from the file system.

This is useful when information about the file system is collected in a worker thread, and then passed to the UI in the form of caching https:// instances.

This function was introduced in Qt 6.0.

See Also▲

See also https://(), https://()

QString QFileInfo::suffix() const▲

Returns the suffix (extension) of the file.

The suffix consists of all characters in the file after (but not including) the last '.'.

Example:

 
Sélectionnez
QFileInfo fi("/tmp/archive.tar.gz");
QString ext = fi.suffix();  // ext = "gz"

The suffix of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc").

See Also▲

See also https://(), https://(), https://(), https://()

void QFileInfo::swap(QFileInfo &other)▲

Swaps this file info with other. This function is very fast and never fails.

QString QFileInfo::symLinkTarget() const▲

Returns the absolute path to the file or directory a symbolic link points to, or an empty string if the object isn't a symbolic link.

This name may not represent an existing file; it is only a string. https://() returns true if the symlink points to an existing file.

See Also▲

See also https://(), https://(), https://(), https://()

bool QFileInfo::operator!=(const QFileInfo &fileinfo) const▲

Returns true if this https:// object refers to a different file than the one specified by fileinfo; otherwise returns false.

See Also▲

See also https://()

QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo)▲

Makes a copy of the given fileinfo and assigns it to this https://.

QFileInfo &QFileInfo::operator=(QFileInfo &&other)▲

Move-assigns other to this https:// instance.

bool QFileInfo::operator==(const QFileInfo &fileinfo) const▲

Returns true if this https:// object refers to a file in the same location as fileinfo; otherwise returns false.

Note that the result of comparing two empty https:// objects, containing no file references (file paths that do not exist or are empty), is undefined.

This will not compare two different symbolic links pointing to the same file.

Long and short file names that refer to the same file on Windows are treated as if they referred to different files.

See Also▲

See also https://()

Related Non-Members▲

 

QFileInfoList▲

Synonym for https://<https://>.

Macro Documentation▲

 

[since 6.0] QT_IMPLICIT_QFILEINFO_CONSTRUCTION▲

Defining this macro makes most https:// constructors implicit instead of explicit. Since construction of https:// objects is expensive, one should avoid accidentally creating them, especially if cheaper alternatives exist. For instance:

 
Sélectionnez
QDirIterator it(dir);
while (it.hasNext()) {
    // Implicit conversion from QString (returned by it.next()):
    // may create unnecessary data structures and cause additional
    // accesses to the file system. Unless this macro is defined,
    // this line does not compile.

    QFileInfo fi = it.next();

    ~~~
}

Instead, use the right API:

 
Sélectionnez
QDirIterator it(dir);
while (it.hasNext()) {
    // Extract the QFileInfo from the iterator directly:
    QFileInfo fi = it.nextFileInfo();

    ~~~
}

Construction from https://, https://, and so on is always possible by using direct initialization instead of copy initialization:

 
Sélectionnez
QFileInfo fi1 = some_string; // Does not compile unless this macro is defined
QFileInfo fi2(some_string);  // OK
QFileInfo fi3{some_string};  // Possibly better, avoids the risk of the Most Vexing Parse
auto fi4 = QFileInfo(some_string); // OK

This macro is provided for compatibility reason. Its usage is not recommended in new code.

This macro was introduced in Qt 6.0.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.