Extending Qt Creator Manual | MimeType

Extending Qt Creator Manual 4.7.0

# MimeType Class

(Utils::MimeType)

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

Header: | #include <MimeType>
Since: | Qt 5.0

- List of all members, including inherited members

## Public Functions

| MimeType()
| MimeType(const Utils::MimeType &other)
| MimeType(const Internal::MimeTypePrivate &dd)
| ~MimeType()
QStringList | aliases() const
QStringList | allAncestors() const
QString | comment() const
QString | filterString() const
QString | genericIconName() const
QStringList | globPatterns() const
QString | iconName() const
bool | inherits(const QString &mimeTypeName) const
bool | isDefault() const
bool | isValid() const
bool | matchesName(const QString &nameOrAlias) const
QString | name() const
QStringList | parentMimeTypes() const
QString | preferredSuffix() const
void | setPreferredSuffix(const QString &suffix)
QStringList | suffixes() const
bool | operator!=(const Utils::MimeType &other) const
Utils::MimeType & | operator=(const Utils::MimeType &other)
bool | operator==(const Utils::MimeType &other) const

## Detailed Description

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

For instance a file named "readme.txt" has the MIME type "text/plain". The MIME type can be determined from the file name, or from the file contents, or from both. MIME type determination can also be done on buffers of data not coming from files.

Determining the MIME type of a file can be useful to make sure your application supports it. It is also useful in file-manager-like applications or widgets, in order to display an appropriate icon for the file, or even the descriptive comment in detailed views.

To check if a file has the expected MIME type, you should use inherits() rather than a simple string comparison based on the name(). This is because MIME types can inherit from each other: for instance a C source file is a specific type of plain text file, so text/x-csrc inherits text/plain.

See also MimeDatabase.

## Member Function Documentation

### MimeType::MimeType()

Default constructs an instance of MimeType.

### MimeType::MimeType(const Utils::MimeType &other)

Default constructs an instance of MimeType.

### MimeType::MimeType(const Internal::MimeTypePrivate &dd)

Default constructs an instance of MimeType.

### MimeType::~MimeType()

Destroys the instance of MimeType.

### QStringList MimeType::aliases() const

Return the list of aliases of this mimetype.

For instance, for text/csv, the returned list would be: text/x-csv, text/x-comma-separated-values.

Note that all MimeType instances refer to proper mimetypes, never to aliases directly.

The order of the aliases in the list is undefined.

### QStringList MimeType::allAncestors() const

Return all the parent mimetypes of this mimetype, direct and indirect. This includes the parent(s) of its parent(s), etc.

For instance, for image/svg+xml the list would be: application/xml, text/plain, application/octet-stream.

Note that application/octet-stream is the ultimate parent for all types of files (but not directories).

### QString MimeType::comment() const

Returns the description of the MIME type to be displayed on user interfaces.

The system language (QLocale::system().name()) is used to select the appropriate translation.

### QString MimeType::filterString() const

### QString MimeType::genericIconName() const

### QStringList MimeType::globPatterns() const

### QString MimeType::iconName() const

### bool MimeType::inherits(const QString &mimeTypeName) const

### bool MimeType::isDefault() const

### bool MimeType::isValid() const

### bool MimeType::matchesName(const QString &nameOrAlias) const

### QString MimeType::name() const

### QStringList MimeType::parentMimeTypes() const

A type is a subclass of another type if any instance of the first type is also an instance of the second. For example, all image/svg+xml files are also text/xml, text/plain and application/octet-stream files. Subclassing is about the format, rather than the category of the data (for example, there is no 'generic spreadsheet' class that all spreadsheets inherit from). Conversely, the parent mimetype of image/svg+xml is text/xml.

A mimetype can have multiple parents. For instance application/x-perl has two parents: application/x-executable and text/plain. This makes it possible to both execute perl scripts, and to open them in text editors.

### QString MimeType::preferredSuffix() const

Returns the preferred suffix for the MIME type. No leading dot is included, so for instance this would return "pdf" for application/pdf. The return value can be empty, for mime types which do not have any suffixes associated.

See also setPreferredSuffix().

### void MimeType::setPreferredSuffix(const QString &suffix)

See also preferredSuffix().

### QStringList MimeType::suffixes() const

Returns the known suffixes for the MIME type. No leading dot is included, so for instance this would return "jpg", "jpeg" for image/jpeg.

### bool MimeType::operator!=(const Utils::MimeType &other) const

### Utils::MimeType &MimeType::operator=(const Utils::MimeType &other)

Copy-assignment operator.

### bool MimeType::operator==(const Utils::MimeType &other) const