QWindowsMimeConverter Class
The QWindowsMimeConverter class maps open-standard MIME to Window Clipboard formats. More...
Header: | #include <QWindowsMimeConverter> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
Public Functions
QWindowsMimeConverter() | |
virtual | ~QWindowsMimeConverter() |
Static Public Members
int | registerMimeType(const QString &mimeType) |
Detailed Description
Qt's drag-and-drop and clipboard facilities use the MIME standard. On X11, this maps trivially to the Xdnd protocol, but on Windows although some applications use MIME types to describe clipboard formats, others use arbitrary non-standardized naming conventions, or unnamed built-in formats of Windows.
By instantiating subclasses of QWindowsMimeConverter that provide conversions between Windows Clipboard and MIME formats, you can convert proprietary clipboard formats to MIME formats.
Construct an instance of your converter implementation after instantiating QGuiApplication:
int main(int argc, char **argv) { QGuiApplication app(argc, argv); JsonMimeConverter jsonConverter; }
Destroying the instance will unregister the converter and remove support for the conversion. It is also valid to heap-allocate the converter instance; Qt takes ownership and will delete the converter object during QGuiApplication shut-down.
Qt has predefined support for the following Windows Clipboard formats:
Windows Format | Equivalent MIME type |
---|---|
CF_UNICODETEXT | text/plain |
CF_TEXT | text/plain |
CF_DIB | image/xyz , where xyz is a Qt image format |
CF_HDROP | text/uri-list |
CF_INETURL | text/uri-list |
CF_HTML | text/html |
An example use of this class would be to map the Windows Metafile clipboard format (CF_METAFILEPICT
) to and from the MIME type image/x-wmf
. This conversion might simply be adding or removing a header, or even just passing on the data. See Drag and Drop for more information on choosing and definition MIME types.
You can check if a MIME type is convertible using canConvertFromMime() and can perform conversions with convertToMime() and convertFromMime().
Member Function Documentation
QWindowsMimeConverter::QWindowsMimeConverter()
Constructs a QWindowsMimeConverter instance.
The instance is automatically registered, and will be called to convert data during clipboard or drag'n'drop operations.
Call this constructor after QGuiApplication has been created.
[virtual noexcept]
QWindowsMimeConverter::~QWindowsMimeConverter()
Constructs a QWindowsMimeConverter instance.
The instance is automatically unregistered.
[static]
int QWindowsMimeConverter::registerMimeType(const QString &mimeType)
Registers the MIME type mimeType, and returns an ID number identifying the format on Windows.
A mime type application/x-qt-windows-mime;value="WindowsType"
will be registered as the clipboard format for WindowsType
.