Is there a known problem with QMimeData on Mac OS X?
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:
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
}
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
Re: Is there a known problem with QMimeData on Mac OS X?
Quote:
Originally Posted by
Wurgl
Is this a known bug or is there a need for some special handling of the class QMimeData on OSX?
I suggest you check the tasktracker.
Re: Is there a known problem with QMimeData on Mac OS X?
Quote:
Originally Posted by
wysota
When searching for QMimeData I did not find anything which smells similar :confused:
Re: Is there a known problem with QMimeData on Mac OS X?
Try upgrading your Qt installation (4.3.4 is the latest stable release).
Re: Is there a known problem with QMimeData on Mac OS X?
Quote:
Originally Posted by
wysota
Try upgrading your Qt installation (4.3.4 is the latest stable release).
The duples are gone. Now I see just one plain/text entry in the clipboard. This does not really solve my problem, since I would like to get the html-source similar to the other two platforms.
I do not know how the textedit application (distributed with Mac OSX) handles it, but this programm is able to receive the html-code from at least safari with the same sequence of <Apple>A/<Apple>C and <Apple>V in the textedit window. It looks a little bit like garbage, but it contains links (and this is what I would like to get).
Re: Is there a known problem with QMimeData on Mac OS X?
On my mac i use.....
qmake -v
QMake version 2.01a
Using Qt version 4.4.0-snapshot-20070608 in /usr/local/Trolltech/Qt-4.4.0-snapshot-20070608/lib
and its run OK
try to build
http://code.google.com/p/qxhtml-edit/
only append text plain ...
http://qxhtml-edit.googlecode.com/sv...c/qvimedit.cpp
Code:
void QVimedit
::insertFromMimeData ( const QMimeData * source
) {
//////////qDebug() << "### insertFromMimeData 2 ";
if ( source->hasImage() ) {
numerobase++;
QImage images
= qvariant_cast<QImage>
(source
->imageData
());
bool salvato = images.save(nuovaim,"PNG",100);
//////////////////qDebug() << "### salvato 1/0 " << salvato;
emit TakeImage(nuovaim); /* and remove nuovaim */
return;
}
////////////////QTextEdit::insertFromMimeData(source);
if ( source->formats().contains("text/html") ) {
////////qDebug() << "### incomming paste text/html ";
/* fwriteutf8(QString fullFileName,QString xml) */
QTidy *tidy = new QTidy(); /* QTidy *tidy; */
tidy->Init(tidicaches); /* tidy cache remove on last event */
const QString xhtmlnew
= tidy
->TidyExternalHtml
(draghtml
);
///////fwriteutf8("copy_in.html",xhtmlnew);
textCursor().insertFragment(fragment);
emit IncommingHTML();
return;
}
}
Re: Is there a known problem with QMimeData on Mac OS X?
Patrick, how is the code you pasted related to the problem? The guy just said his QMimeData doesn't contain "text/html", so why the hell do you paste code which runs some tidy clone on html code? How is that relevant?
Re: Is there a known problem with QMimeData on Mac OS X?
Quote:
Originally Posted by
wysota
How is that relevant?
It helps me a little bit. I see now, that the Clipboard on OSX can hold text/plain and text/html at the same time and that Qt/Mac (even Qt 4.2.1) and my code work as expected. So it seems that I have to ask at the project pages of the relevant browsers.
Re: Is there a known problem with QMimeData on Mac OS X?
Quote:
Originally Posted by
Wurgl
I see now, that the Clipboard on OSX can hold text/plain and text/html at the same time and that Qt/Mac and my code work as expected. So it seems that I have to ask at the project pages of the relevant browsers.
Have you seen the "dropsite" example (or demo) bundled with Qt? It's useful for testing mime-types of dragged objects and dragging and pasting from clipboard is using the same technique (you can probably even modify the example to react on pasting as well). And you can see what mime-types are created when you drag data from these applications.