Uniform Type Identifier (UTI) format.">

- Qt 6.5
- Qt GUI
- C++ Classes
- QUtiMimeConverter
- Qt 6.5.1 Reference Documentation

# QUtiMimeConverter Class

The QUtiMimeConverter class converts between a MIME type and a Uniform Type Identifier (UTI) format. More...

Header: | #include <QUtiMimeConverter>
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: | QT += gui
Since: | Qt 6.5

- List of all members, including inherited members

## Public Types

flags | HandlerScope

## Public Functions

| QUtiMimeConverter()
virtual | ~QUtiMimeConverter()
bool | canConvert(const QString &mime, const QString &uti) const
virtual QList<QByteArray> | convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const = 0
virtual QVariant | convertToMime(const QString &mime, const QList<QByteArray> &data, const QString &uti) const = 0
virtual int | count(const QMimeData *mimeData) const
virtual QString | mimeForUti(const QString &uti) const = 0
virtual QString | utiForMime(const QString &mime) const = 0

## Detailed Description

Qt's drag and drop and clipboard facilities use the MIME standard. On X11, this maps trivially to the Xdnd protocol. On Mac, although some applications use MIME to describe clipboard contents, it is more common to use Apple's UTI format.

QUtiMimeConverter's role is to bridge the gap between MIME and UTI; By subclasses this class, one can extend Qt's drag and drop and clipboard handling to convert to and from unsupported, or proprietary, UTI formats.

A subclass of QUtiMimeConverter will automatically be registered, and active, upon instantiation.

Qt has predefined support for the following UTIs:

- public.utf8-plain-text - converts to "text/plain"
- public.utf16-plain-text - converts to "text/plain"
- public.text - converts to "text/plain"
- public.html - converts to "text/html"
- public.url - converts to "text/uri-list"
- public.file-url - converts to "text/uri-list"
- public.tiff - converts to "application/x-qt-image"
- public.vcard - converts to "text/plain"
- com.apple.traditional-mac-plain-text - converts to "text/plain"
- com.apple.pict - converts to "application/x-qt-image"

When working with MIME data, Qt will iterate through all instances of QUtiMimeConverter to find find an instance that can convert to, or from, a specific MIME type. It will do this by calling mimeForUti() or utiForMime() on each instance, starting with (and choosing) the last created instance first. The actual conversions will be done by using convertToMime() and convertFromMime().

## Member Function Documentation

### QUtiMimeConverter::QUtiMimeConverter()

Constructs a new conversion object and adds it to the globally accessed list of available converters.

### `[virtual]` QUtiMimeConverter::~QUtiMimeConverter()

Destroys a conversion object, removing it from the global list of available converters.

### bool QUtiMimeConverter::canConvert(const QString &mime, const QString &uti) const

Returns `true` if the converter can convert (both ways) between mime and uti; otherwise returns `false`.

### `[pure virtual]` QList<QByteArray> QUtiMimeConverter::convertFromMime(const QString &mime, const QVariant &data, const QString &uti) const

Returns data converted from MIME type mime to Mac UTI uti.

Note that Mac UTIs must all be self-terminating. The return value may contain trailing data.

All subclasses must reimplement this pure virtual function.

### `[pure virtual]` QVariant QUtiMimeConverter::convertToMime(const QString &mime, const QList<QByteArray> &data, const QString &uti) const

Returns data converted from Mac UTI uti to MIME type mime.

Note that Mac UTIs must all be self-terminating. The input data may contain trailing data.

All subclasses must reimplement this pure virtual function.

### `[virtual]` int QUtiMimeConverter::count(const QMimeData *mimeData) const

Returns the item count for the given mimeData

### `[pure virtual]` QString QUtiMimeConverter::mimeForUti(const QString &uti) const

Returns the MIME type used for Mac UTI uti, or an empty string if this converter does not support converting from uti.

All subclasses must reimplement this pure virtual function.

### `[pure virtual]` QString QUtiMimeConverter::utiForMime(const QString &mime) const

Returns the Mac UTI used for MIME type mime, or an empty string if this converter does not support converting from mime.

All subclasses must reimplement this pure virtual function.