![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qmimedata.h>
Public Member Functions | |
QMimeData () | |
Constructs a new MIME data object with no data in it. | |
~QMimeData () | |
Destroys the MIME data object. | |
QList< QUrl > | urls () const |
Returns a list of URLs contained within the MIME data object. | |
void | setUrls (const QList< QUrl > &urls) |
Sets the URLs stored in the MIME data object to those specified by urls. | |
bool | hasUrls () const |
Returns true if the object can return a list of urls; otherwise returns false . | |
QString | text () const |
Returns a plain text (MIME type text/plain ) representation of the data. | |
void | setText (const QString &text) |
Sets text as the plain text (MIME type text/plain ) used to represent the data. | |
bool | hasText () const |
Returns true if the object can return plain text (MIME type text/plain ); otherwise returns false . | |
QString | html () const |
Returns a string if the data stored in the object is HTML (MIME type text/html ); otherwise returns an empty string. | |
void | setHtml (const QString &html) |
Sets html as the HTML (MIME type text/html ) used to represent the data. | |
bool | hasHtml () const |
Returns true if the object can return HTML (MIME type text/html ); otherwise returns false . | |
QVariant | imageData () const |
Returns a QVariant storing a QImage if the object can return an image; otherwise returns a null variant. | |
void | setImageData (const QVariant &image) |
Sets the data in the object to the given image. | |
bool | hasImage () const |
Returns true if the object can return an image; otherwise returns false. | |
QVariant | colorData () const |
Returns a color if the data stored in the object represents a color (MIME type application/x-color ); otherwise returns a null variant. | |
void | setColorData (const QVariant &color) |
Sets the color data in the object to the given color. | |
bool | hasColor () const |
Returns true if the object can return a color (MIME type application/x-color ); otherwise returns false . | |
QByteArray | data (const QString &mimetype) const |
Returns the data stored in the object in the format described by the MIME type specified by mimeType. | |
void | setData (const QString &mimetype, const QByteArray &data) |
Sets the data associated with the MIME type given by mimeType to the specified data. | |
void | removeFormat (const QString &mimetype) |
virtual bool | hasFormat (const QString &mimetype) const |
Returns true if the object can return data for the MIME type specified by mimeType; otherwise returns false . | |
virtual QStringList | formats () const |
Returns a list of formats supported by the object. | |
void | clear () |
Removes all the MIME type and data entries in the object. | |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Protected Member Functions | |
virtual QVariant | retrieveData (const QString &mimetype, QMetaType preferredType) const |
Returns a variant with the given type containing data for the MIME type specified by mimeType. | |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Additional Inherited Members | |
![]() | |
void | deleteLater () |
\threadsafe | |
![]() | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
![]() | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
![]() | |
QString | objectName |
the name of this object | |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
\inmodule QtCore
The QMimeData class provides a container for data that records information about its MIME type.
QMimeData is used to describe information that can be stored in the \l{QClipboard}{clipboard}, and transferred via the \l{drag and drop} mechanism. QMimeData objects associate the data that they hold with the corresponding MIME types to ensure that information can be safely transferred between applications, and copied around within the same application.
QMimeData objects are usually created using new
and supplied to QDrag or QClipboard objects. This is to enable Qt to manage the memory that they use.
A single QMimeData object can store the same data using several different formats at the same time. The formats() function returns a list of the available formats in order of preference. The data() function returns the raw data associated with a MIME type, and setData() allows you to set the data for a MIME type.
For the most common MIME types, QMimeData provides convenience functions to access the data:
\table \header
text/plain
\row text/html
\row text/uri-list
\row image/
* \row application/x-color
\endtableFor example, if your write a widget that accepts URL drags, you would end up writing code like this:
There are three approaches for storing custom data in a QMimeData object:
\list 1
\endlist
Definition at line 15 of file qmimedata.h.
QMimeData::QMimeData | ( | ) |
Constructs a new MIME data object with no data in it.
Definition at line 304 of file qmimedata.cpp.
QMimeData::~QMimeData | ( | ) |
Destroys the MIME data object.
Definition at line 312 of file qmimedata.cpp.
void QMimeData::clear | ( | ) |
Removes all the MIME type and data entries in the object.
Definition at line 637 of file qmimedata.cpp.
References d.
Referenced by QHaikuClipboard::mimeData(), QQnxClipboard::mimeData(), QtWayland::DataDeviceManager::overrideSelection(), QInternalMimeData::retrieveData(), QtWayland::DataDeviceManager::setCurrentSelectionSource(), and QQnxClipboard::setMimeData().
QVariant QMimeData::colorData | ( | ) | const |
Returns a color if the data stored in the object represents a color (MIME type application/x-color
); otherwise returns a null variant.
A QVariant is used because QMimeData belongs to the Qt Core module, whereas QColor belongs to Qt GUI. To convert the QVariant to a QColor, simply use qvariant_cast(). For example:
Definition at line 506 of file qmimedata.cpp.
References applicationXColorLiteral(), and d.
Referenced by QWaylandMimeHelper::getByteArray(), and operator<<().
QByteArray QMimeData::data | ( | const QString & | mimetype | ) | const |
Returns the data stored in the object in the format described by the MIME type specified by mimeType.
Definition at line 541 of file qmimedata.cpp.
Referenced by commonCopyEvent(), QWaylandMimeHelper::getByteArray(), QWindowsOleDataObject::mimeData(), QtWayland::DataDeviceManager::overrideSelection(), QHaikuClipboard::setMimeData(), QMacPasteboard::setMimeData(), ClipWindow::updateClipboard(), ClipWindow::updateData(), and QXcbDropData::xdndObtainData().
|
virtual |
Returns a list of formats supported by the object.
This is a list of MIME types for which the object can return suitable data. The formats in the list are in a priority order.
For the most common types of data, you can call the higher-level functions hasText(), hasHtml(), hasUrls(), hasImage(), and hasColor() instead.
Reimplemented in QInternalMimeData, QMacPasteboardMimeSource, QIOSMimeData, QQnxClipboard::MimeData, QTextEditMimeData, and QQuickTextEditMimeData.
Definition at line 602 of file qmimedata.cpp.
References d, e, list, and QList< T >::reserve().
Referenced by QtWaylandClient::QWaylandPrimarySelectionSourceV1::QWaylandPrimarySelectionSourceV1(), QWindowsOleDataObject::QWindowsOleDataObject(), QBuiltInMimes::canConvertFromMime(), commonCopyEvent(), QTextEditMimeData::formats(), QQuickTextEditMimeData::formats(), QBuiltInMimes::formatsForMime(), QQuickDropAreaPrivate::getKeys(), hasFormat(), QtWayland::DataDeviceManager::offerFromCompositorToClient(), QtWayland::DataDeviceManager::offerRetainedSelection(), operator<<(), QtWayland::DataDeviceManager::overrideSelection(), QHaikuClipboard::setMimeData(), QWindowsClipboard::setMimeData(), QMacPasteboard::setMimeData(), and ClipWindow::updateClipboard().
bool QMimeData::hasColor | ( | ) | const |
Returns true
if the object can return a color (MIME type application/x-color
); otherwise returns false
.
Definition at line 532 of file qmimedata.cpp.
References applicationXColorLiteral(), and hasFormat().
Referenced by operator<<().
|
virtual |
Returns true
if the object can return data for the MIME type specified by mimeType; otherwise returns false
.
For the most common types of data, you can call the higher-level functions hasText(), hasHtml(), hasUrls(), hasImage(), and hasColor() instead.
Reimplemented in QInternalMimeData, and QQnxClipboard::MimeData.
Definition at line 586 of file qmimedata.cpp.
References formats(), and mimeType.
Referenced by hasColor(), hasHtml(), hasImage(), hasText(), hasUrls(), and QXcbMime::mimeDataForAtom().
bool QMimeData::hasHtml | ( | ) | const |
Returns true
if the object can return HTML (MIME type text/html
); otherwise returns false
.
Definition at line 442 of file qmimedata.cpp.
References hasFormat(), and textHtmlLiteral().
Referenced by commonCopyEvent(), operator<<(), and droparea::DropArea::paste().
bool QMimeData::hasImage | ( | ) | const |
Returns true
if the object can return an image; otherwise returns false.
Definition at line 488 of file qmimedata.cpp.
References applicationXQtImageLiteral(), and hasFormat().
Referenced by QWindowsMimeImage::canConvertFromMime(), QWindowsMimeImage::convertFromMime(), QWindowsMimeImage::formatsForMime(), QWaylandMimeHelper::getByteArray(), QXcbDrag::handleDrop(), QXcbMime::mimeDataForAtom(), operator<<(), and droparea::DropArea::paste().
bool QMimeData::hasText | ( | ) | const |
Returns true
if the object can return plain text (MIME type text/plain
); otherwise returns false
.
Definition at line 406 of file qmimedata.cpp.
References hasFormat(), hasUrls(), and textPlainLiteral().
Referenced by QWindowsMimeText::canConvertFromMime(), QQuickTextInput::canPaste(), commonCopyEvent(), QWindowsMimeText::formatsForMime(), operator<<(), and droparea::DropArea::paste().
bool QMimeData::hasUrls | ( | ) | const |
Returns true
if the object can return a list of urls; otherwise returns false
.
URLs correspond to the MIME type text/uri-list
.
Definition at line 365 of file qmimedata.cpp.
References hasFormat(), and textUriListLiteral().
Referenced by QWindowsMimeURI::canConvertFromMime(), hasText(), and operator<<().
QString QMimeData::html | ( | ) | const |
Returns a string if the data stored in the object is HTML (MIME type text/html
); otherwise returns an empty string.
Definition at line 417 of file qmimedata.cpp.
References d, and textHtmlLiteral().
Referenced by QWindowsMimeHtml::canConvertFromMime(), commonCopyEvent(), QWindowsMimeHtml::convertFromMime(), QBuiltInMimes::convertFromMime(), QWindowsMimeHtml::formatsForMime(), operator<<(), droparea::DropArea::paste(), and setHtml().
QVariant QMimeData::imageData | ( | ) | const |
Returns a QVariant storing a QImage if the object can return an image; otherwise returns a null variant.
A QVariant is used because QMimeData belongs to the Qt Core module, whereas QImage belongs to Qt GUI. To convert the QVariant to a QImage, simply use qvariant_cast(). For example:
Definition at line 459 of file qmimedata.cpp.
References applicationXQtImageLiteral(), and d.
Referenced by QWindowsMimeImage::canConvertFromMime(), QWindowsMimeImage::convertFromMime(), QWindowsMimeImage::formatsForMime(), QWaylandMimeHelper::getByteArray(), operator<<(), and droparea::DropArea::paste().
Removes the data entry for mimeType in the object.
Definition at line 648 of file qmimedata.cpp.
|
protectedvirtual |
Returns a variant with the given type containing data for the MIME type specified by mimeType.
If the object does not support the MIME type or variant type given, a null variant is returned instead.
This function is called by the general data() getter and by the convenience getters (text(), html(), urls(), imageData(), and colorData()). You can reimplement it if you want to store your data using a custom data structure (instead of a QByteArray, which is what setData() provides). You would then also need to reimplement hasFormat() and formats().
Reimplemented in QMacPasteboardMimeSource, QQnxClipboard::MimeData, QInternalMimeData, QIOSMimeData, QTextEditMimeData, and QQuickTextEditMimeData.
Definition at line 627 of file qmimedata.cpp.
References d, mimeType, and Q_UNUSED.
Referenced by QQnxClipboard::MimeData::retrieveData(), QInternalMimeData::retrieveData(), QTextEditMimeData::retrieveData(), QQuickTextEditMimeData::retrieveData(), and QMacMimeData::variantData().
Sets the color data in the object to the given color.
Colors correspond to the MIME type application/x-color
.
Definition at line 519 of file qmimedata.cpp.
References applicationXColorLiteral(), and d.
void QMimeData::setData | ( | const QString & | mimeType, |
const QByteArray & | data | ||
) |
Sets the data associated with the MIME type given by mimeType to the specified data.
For the most common types of data, you can call the higher-level functions setText(), setHtml(), setUrls(), setImageData(), and setColorData() instead.
Note that if you want to use a custom data type in an item view drag and drop operation, you must register it as a Qt \l{QMetaType}{meta type}, using the Q_DECLARE_METATYPE() macro, and implement stream operators for it.
Definition at line 562 of file qmimedata.cpp.
References ba, QByteArray::chop(), d, dataToUrls(), QByteArray::endsWith(), and mimeType.
Referenced by QQuickDragAttachedPrivate::createMimeData(), QCocoaDrag::drag(), DragDropListModel::mimeData(), QHaikuClipboard::mimeData(), DragWidget::mouseMoveEvent(), FinalWidget::mouseMoveEvent(), QtWayland::DataDeviceManager::overrideSelection(), and QInternalMimeData::retrieveData().
Sets html as the HTML (MIME type text/html
) used to represent the data.
Definition at line 430 of file qmimedata.cpp.
References d, html(), and textHtmlLiteral().
Referenced by QQuickDragAttachedPrivate::createMimeData(), and QHaikuClipboard::mimeData().
Sets the data in the object to the given image.
A QVariant is used because QMimeData belongs to the Qt Core module, whereas QImage belongs to Qt GUI. The conversion from QImage to QVariant is implicit. For example:
Definition at line 476 of file qmimedata.cpp.
References applicationXQtImageLiteral(), and d.
Referenced by QQuickDragAttachedPrivate::createMimeData(), QClipboard::setImage(), QClipboard::setPixmap(), and src_gui_kernel_qclipboard::wrapper().
Sets text as the plain text (MIME type text/plain
) used to represent the data.
Definition at line 394 of file qmimedata.cpp.
References d, text(), and textPlainLiteral().
Referenced by QWidgetTextControlPrivate::_q_copyLink(), QQuickDragAttachedPrivate::createMimeData(), QtAndroidClipboard::getClipboardMimeData(), QHaikuClipboard::mimeData(), MainWindow::mousePressEvent(), and QClipboard::setText().
Sets the URLs stored in the MIME data object to those specified by urls.
URLs correspond to the MIME type text/uri-list
.
Since Qt 5.0, setUrls also exports the urls as plain text, if setText was not called before, to make it possible to drop them into any lineedit and text editor.
Definition at line 351 of file qmimedata.cpp.
References QList< T >::cbegin(), QList< T >::cend(), d, textUriListLiteral(), and urls().
Referenced by QQuickDragAttachedPrivate::createMimeData().
QString QMimeData::text | ( | ) | const |
Returns a plain text (MIME type text/plain
) representation of the data.
Definition at line 377 of file qmimedata.cpp.
References d, QVariant::isNull(), textPlainLiteral(), textPlainUtf8Literal(), and QVariant::toString().
Referenced by commonCopyEvent(), QWindowsMimeText::convertFromMime(), QWaylandMimeHelper::getByteArray(), operator<<(), droparea::DropArea::paste(), and setText().
Returns a list of URLs contained within the MIME data object.
URLs correspond to the MIME type text/uri-list
.
Definition at line 323 of file qmimedata.cpp.
References QList< T >::append(), QList< T >::at(), d, i, list, QList< T >::size(), textUriListLiteral(), QList< T >::toList(), and urls().
Referenced by QWindowsMimeURI::canConvertFromMime(), QWindowsMimeURI::convertFromMime(), QMacMimeFileUri::count(), QWaylandMimeHelper::getByteArray(), QXcbMime::mimeConvertToFormat(), operator<<(), setUrls(), and urls().