6.0.0-rc4Source

QMimeType Class

The QMimeType class describes types of file or data, represented by a MIME type string. More…

Header#include <QMimeType>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
Since5.0

List of all members, including inherited members

Public Functions

QMimeType()
QMimeType(const QMimeType &other)
QMimeType &operator=(const QMimeType &other)
QMimeType(QMimeType &&other)
QMimeType &operator=(QMimeType &&other)
~QMimeType()
voidswap(QMimeType &other)
boolisValid() const
boolisDefault() const
QStringname() const
QStringcomment() const
QStringgenericIconName() const
QStringiconName() const
QStringListglobPatterns() const
QStringListparentMimeTypes() const
QStringListallAncestors() const
QStringListaliases() const
QStringListsuffixes() const
QStringpreferredSuffix() const
boolinherits(const QString &mimeTypeName) const
QStringfilterString() const

Detailed Description

A QMimeType is a type of QMimeDatabase: its name, such as text/html, a description for people, the patterns of file names that it has, its icons, and the types that it is a kind of. Get one from QMimeDatabase:

const QMimeType type = QMimeDatabase().mimeTypeForName(u"image/svg+xml"_s);
type.comment();         // "SVG image"
type.preferredSuffix(); // "svg"
type.inherits(u"application/xml"_s); // true

A QMimeType is small: it holds the name of the type and asks the database for the rest.

See also QMimeDatabase.

Differences from Qt

The properties are read from the database each time, so they change if the database is reloaded. The functions that take a name take a const QString &.

Member Function Documentation

QMimeType::QMimeType()

Constructs an invalid type.

See also isValid().

QMimeType::QMimeType(const QMimeType &other)

Constructs a copy of other.

QMimeType::QMimeType(QMimeType &&other)

Move-constructs a type from other, which becomes invalid.

QMimeType::~QMimeType()

Destroys the type.

QStringList QMimeType::aliases() const

Returns the other names of the type, which QMimeDatabase::mimeTypeForName() also finds it by.

QStringList QMimeType::allAncestors() const

Returns the types that this type is a kind of, directly or through others, the closest first.

See also parentMimeTypes().

QString QMimeType::comment() const

Returns the description of the type for people, in the language of the default locale if the database has it, such as PNG image. A type without a description gives its name.

QString QMimeType::filterString() const

Returns a filter for a file dialog, such as PNG image (*.png): the description and the patterns of the names. It is empty for a type without patterns.

QString QMimeType::genericIconName() const

Returns the name of the icon of the group of types that this type belongs to, such as image-x-generic. Without one in the database, it is the media type followed by -x-generic.

See also iconName().

QStringList QMimeType::globPatterns() const

Returns the patterns of the names of files of this type, such as *.png.

See also suffixes().

QString QMimeType::iconName() const

Returns the name of the icon of the type, in the icon themes of freedesktop.org. Without one in the database, it is the name of the type with the slash replaced by a dash, such as image-png.

See also genericIconName().

bool QMimeType::inherits(const QString &mimeTypeName) const

Returns true if this type is mimeTypeName, or one of its aliases, or a kind of it, directly or through others.

See also allAncestors().

bool QMimeType::isDefault() const

Returns true if this is application/octet-stream, the type of data whose type is not known.

bool QMimeType::isValid() const

Returns true if the type is one of the database. A type that QMimeDatabase did not find is invalid.

QString QMimeType::name() const

Returns the name of the type, such as image/png.

QMimeType & QMimeType::operator=(const QMimeType &other)

Assigns other to this type and returns a reference to it.

QMimeType & QMimeType::operator=(QMimeType &&other)

Move-assigns other to this type and returns a reference to it.

QStringList QMimeType::parentMimeTypes() const

Returns the types that this type is a kind of, directly. A text type without others is a kind of text/plain, and any other type that is not a directory a kind of application/octet-stream.

See also allAncestors() and inherits().

QString QMimeType::preferredSuffix() const

Returns the suffix that a file of this type is given when it is saved, the first of suffixes(), or an empty string.

QStringList QMimeType::suffixes() const

Returns the suffixes of the names of files of this type, without the dot: those of the patterns that are *. followed by a suffix.

See also preferredSuffix() and globPatterns().

void QMimeType::swap(QMimeType &other)

Exchanges this type with other.