[Interest] Subclassing QMacPasteboardMime

Adam Light aclight at gmail.com
Tue May 29 21:09:48 CEST 2012


In case anyone else encounters this, I've filed a bug report on this issue
at https://bugreports.qt-project.org/browse/QTBUG-25951

On Thu, May 24, 2012 at 1:52 PM, Adam Light <aclight at gmail.com> wrote:

> In my application, I wish to handle tiff clipboard data (of UTI type
> public.tiff) different than the implementation in QMacPasteboardMimeTiff (I
> don't want the data to pass through a QImage).
>
> I have written my own subclass of QMacPasteboardMime that does exactly
> what I want, and it works correctly.
>
> The documentation of QMacPasteboardMime (http://qt-project.org/doc/qt-4.8/
> qmacpasteboardmime.html) states:
> "When working with MIME data, Qt will interate through all instances of
> QMacPasteboardMime to find an instance that can convert to, or from, a
> specific MIME type. It will do this by calling canConvert() on each
> instance, starting with (and choosing) the last created instance first. The
> actual conversions will be done by using convertToMime()
> and convertFromMime()."
>
> I am instantiating my subclass of QMacPasteboardMime (call it
> MyMacPasteboardMimeTiff) after my application's QApplication object is
> created (the base QMacPasteboardMime class is created in the QApplication
> initialization code).
>
> My problem is that my MyMacPasteboardMimeTiff::mimeFor(), canConvert(),
> etc. methods never get called. This is because QMacPasteboardMime::flavorToMime(),
> which gets called when QMimeData::formats() is called, uses this code:
>
> QString QMacPasteboardMime::flavorToMime(uchar t, QString flav)
>
> {
>
>     MimeList *mimes = globalMimeList();
>
>     for(MimeList::const_iterator it = mimes->constBegin(); it != mimes->constEnd(); ++it) {
>
> #ifdef DEBUG_MIME_MAPS
>
>         qDebug("QMacMIme::flavorToMime: attempting %s (%d) for flavor %d[%c%c%c%c] [%s]",
>
>                (*it)->convertorName().toLatin1().constData(),
>
>                (*it)->type & t, flav, (flav >> 24) & 0xFF, (flav >> 16) & 0xFF, (flav >> 8) & 0xFF, (flav) & 0xFF,
>
>                (*it)->mimeFor(flav).toLatin1().constData());
>
>
> #endif
>
>         if((*it)->type & t) {
>
>             QString mimeType = (*it)->mimeFor(flav);
>
>             if(!mimeType.isNull())
>
>                 return mimeType;
>
>         }
>
>     }
>
>     return QString();
>
> }
>
>
> So contrary to what the documentation
> states/implies, QMacPasteboardMimeTiff::mimeFor() ends up getting called
> before MyMacPasteboardMimeTiff::mimeFor() gets called.
> Since QMacPasteboardMimeTiff supports the public.tiff UTI, it ends up being
> used to do the conversion from the clipboard's data to MIME data.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120529/513be5d6/attachment.html>


More information about the Interest mailing list