1. QMimeData说明
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 clipboard, and transferred via the 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类提为数据提供一个容器,用来记录关于MIME类型数据的信息
QMimeData常用来描述保存在剪切板里信息,或者拖拽原理
QMimeData对象把它所保存的信息和正确的MIME类型连接起来来保证信息可以被安全的在应用程序之间转移,或者在同一个应用程序之间拷贝
QMimeData对象通产雇佣new来创建,并且支持QDrag和QClipboard对象,这可以使QT管理他们所使用的内存
- 对于大多数MIME类型,QMimeData提供方便的函数来获取数据
例子
1)void MyWidget::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasUrls())
event->acceptProposedAction();
}void MyWidget::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasUrls()) {
foreach (QUrl url, event->mimeData()->urls()) {
…
}
}
}
2)
void MyWidget::dropEvent(QDropEvent *event)
{
const MyMimeData *myData=
qobject_cast