It seems, that QMimeData on Mac OSX (Qt 4.2.1) is a little bit confused when the clipboard holds multiple formats. When select & copy a whole webpage in different browsers (I tried Safari, Camino, Firefox and Opera), then it shows me, that there are multiple clipboard-formats of type "text/plain".
Here is the relevant part of my code:
#include <iostream>
#include <Qt/qtextedit.h>
#include <Qt/qtextdocumentfragment.h>
#include <Qt/qmimedata.h>
{
public:
void insertFromMimeData
(const QMimeData *source
);
};
void MyTextEdit
::insertFromMimeData(const QMimeData *source
) {
if (!source)
return;
for(int i = 0; i < formats.size(); ++ i) {
std::cerr << "Mime Format: " << formats.at(i).toStdString() << std::endl;
}
std::cerr << "source->hasHtml(): " << source->hasHtml() << std::endl;
// ... insert here the real body
}
#include <iostream>
#include <Qt/qtextedit.h>
#include <Qt/qtextdocumentfragment.h>
#include <Qt/qmimedata.h>
class MyTextEdit : public QTextEdit
{
public:
void insertFromMimeData(const QMimeData *source);
};
void MyTextEdit::insertFromMimeData(const QMimeData *source)
{
if (!source)
return;
QStringList formats = source->formats();
for(int i = 0; i < formats.size(); ++ i) {
std::cerr << "Mime Format: " << formats.at(i).toStdString() << std::endl;
}
std::cerr << "source->hasHtml(): " << source->hasHtml() << std::endl;
// ... insert here the real body
}
To copy to clipboard, switch view to plain text mode
Now I open some webpage in the browser, on the keyboard I type <Apple>A and <Apple>C (which corresponds to Ctrl-A / Ctrl-C on Windows/Linux) and then <Apple>V in my widget.
Depending on the browser I see:
Browser Camino:
Mime Format: text/plain
Mime Format: text/plain
source->hasHtml(): 0
Firefox:
Mime Format: text/plain
Mime Format: text/plain
source->hasHtml(): 0
Safari: (note, that I get three times text/html)
Mime Format: text/plain
Mime Format: text/plain
Mime Format: text/plain
source->hasHtml(): 0
Opera:
Mime Format: text/plain
Mime Format: text/plain
source->hasHtml(): 0
On Linux I get a lot of different formats, for example Firefox shows this output:
Mime Format: TIMESTAMP
Mime Format: TARGETS
Mime Format: MULTIPLE
Mime Format: text/html
Mime Format: text/_moz_htmlcontext
Mime Format: text/_moz_htmlinfo
Mime Format: UTF8_STRING
Mime Format: text/plain
Mime Format: COMPOUND_TEXT
Mime Format: TEXT
Mime Format: STRING
Mime Format: text/x-moz-url-priv
source->hasHtml(): 1
And with Opear I see this
Mime Format: text/plain;charset=UTF-8
Mime Format: text/plain;charset=ISO-10646-UCS-2
Mime Format: text/plain
Mime Format: text/plain;charset=iso8859-1
Mime Format: UTF8_STRING
Mime Format: TEXT
Mime Format: COMPOUND_TEXT
Mime Format: STRING
Mime Format: TARGETS
Mime Format: MULTIPLE
Mime Format: TIMESTAMP
source->hasHtml(): 0
Similar different mime types can be seen with other browsers on Linux and Windows too.
No I am wondering, why all those four Browsers on OSX add multiple times a mime type of text/plain into the buffer whereas the same browsers use different types on Linux. I do not care for the number of different formats, I am just wondering why I get multiple text/plain.
Is this a known bug or is there a need for some special handling of the class QMimeData on OSX?
Thanks
Bookmarks