Skip to content

QMimeSource and QDropEvent

Ivailo Monev edited this page Nov 24, 2017 · 7 revisions

This was done in https://github.com/fluxer/katie/commit/91dd13aa898c1d236dd8b6aaef7510451ee13a7d and https://github.com/fluxer/katie/commit/9c733a3181d561f585980113306c254382afea8b, the QDropEvent methods were only for compatibility and convenience. QMimeSource on the other side is just redundant now.

All of the functionality is available trough different route without penalty when it comes to performance (there should be improvement in fact) since QDropEvent::mimeData() is marked inline and you should adjust your projects. For an example:

void MyWidget::dropEvent(QDropEvent *event)
{
    if (e->provides("application/x-my-uri")) {
         qDebug() << "Uh, oh.." << e->encodedData("application/x-my-uri");
    }
}

Should be changed to:

void MyWidget::dropEvent(QDropEvent *event)
{
    const QMimeData *em = e->mimeData();
    if (em->hasFormat(QLatin1String("application/x-my-uri"))) {
         qDebug() << "Uh, oh.." << em->data(QLatin1String("application/x-my-uri"));
    }
}

Or even better, with Qt4 compatibility:

void MyWidget::dropEvent(QDropEvent *event)
{
#ifndef QT_KATIE
    if (e->provides("application/x-my-uri")) {
         qDebug() << "Uh, oh.." << e->encodedData("application/x-my-uri");
    }
#else
    if (e->mimeData()->hasFormat(QLatin1String("application/x-my-uri"))) {
         qDebug() << "Uh, oh.." << e->mimeData()->data(QLatin1String("application/x-my-uri"));
    }
#endif
}