[Qt-interest] Drag&Drop on OS X behaves weird
Nikos Chantziaras
realnc at arcor.de
Thu Jan 13 00:30:30 CET 2011
On 01/03/2011 11:09 AM, Oliver.Knoll at comit.ch wrote:
> On 2010-12-31 Nikos Nikos Chantziaras wrote:
>
>> ...
>> void dropEvent( QDropEvent* e )
>> {
>> if (ok_to_open_a_file) {
>> schedule_file_open(e->mimeData()->urls().at(0).toLocalFile());
>> e->acceptProposedAction(); } else { e->ignore();
>> }
>> }
>
> Looks good to me.
>
>> I'm on Qt 4.7.1.
>
> I am on the same Qt version and also on Mac, which is OS X 10.6.5 (latest), I implemented drag'n'drop onto a QGraphicsScene without the mentioned problems (no freezes - will check the keyboard/shortcut input, however so far I did not notice anything strange). However I do not open any files (yet), I check the MIME data for pixmap data and my own data structures, and paste from memory (e.g. an image dragged from Firefox onto my app works without problems). So that is the difference so far between your and my drag'n'drop operation.
>
> What does your "schedule_file_open()" do? I guess that's where the interesting part would be for us to know what could go wrong.
Finally found the cause. It's nasty. schedule_file_open() didn't
actually return until the opened file was closed again. The application
in question is a bit weird in that opening a file means blocks the event
loop. Calls to processEvents() make sure the GUI keeps running. (This
way of working is needed for this type of application; it's a virtual
machine and the files that are opened are bytecode programs to be
executed which naturally have their own event loop.)
To fix the drag&drop issue I had to call schedule_file_open() through
QMetaObject::invokeMethod() so that dropEvent() can actually return
prior to opening the file.
More information about the Qt-interest-old
mailing list