Drag and Drop issues on Windows
-
I'm the developer of OpenKJ, an open source karaoke hosting app. I'm having a weird problem, specifically on Windows. Doesn't happen on Linux or macOS.
I have several QTableViews that are used to display/manipulate rotation singers, song queues, break music playlists, etc. I use subclassed QAbstractTableModels to populate them and handle all of the drag and drop stuff for reordering inside views and for dragging content into them. Everything works perfectly except for on Windows. On that platform, drag and drop works normally on program startup, but after the program has been running for about 20 mins, drag and drop stops working completely. Always shows the drop forbidden symbol and stops calling canDropMimeData in any of the models when dragging items into the views.
Anyone else ever run into this? If so, any idea how to fix it?
Qt version is 5.15.0 using MSVC2019
-
Hi and welcome to devnet,
Do you have any particular check to forbid dropping ?
Does it happen on every widget that are drop targets ?
Which version of Windows are you running ? -
Just the normal mime types checks, but that's in canDropMimeData, which never gets called again once the problem starts happening.
Every drop target in the program is affected (3 different tableviews w/ separate models).
This is Windows 10 Pro, so far all of the users reporting the problem are also on Windows 10.
Source is at https://github.com/openkj/openkj btw
-
Did some deeper digging on this. After the bug is triggered, exceptions start getting thrown as soon as a drag starts. Had to actually load the code up in Visual Studio and use the debugger there to see the exceptions.
Here's the exception it's throwing:
Exception thrown at 0x74FD46D2 (KernelBase.dll) in openkj.exe: 0x80010012: The callee (server [not server application]) is not available and disappeared; all connections are invalid. The call did not execute.The call stack shows that it's triggering on the Qt side after a call to:
const HRESULT r = DoDragDrop(dropDataObject, windowDropSource, allowedEffects, &resultEffect);
from ole32.dll in qwindowsdrag.cpp on line 700 in the QWindowsDrag.cpp file. -
Was able to create a super minimal example.
Seems to be a problem with using Qt and GStreamer together.
-
For anyone who stumbles across this and is having similar issues, here's what was causing the bug.
Qt uses COM for handling drag and drop events on Windows.
GStreamer currently has a bug in their WASAPI audio backend that causes COM objects to be destroyed that it didn't create when some threads exit.
GStreamer was destroying the COM object that Qt was using, causing Qt's drag and drop functionality to stop working.The fix is to make GStreamer default to using DirectSound instead of WASAPI for its audio sink. Add the following code, after you init GStreamer:
#ifdef Q_OS_WIN // Use directsoundsink by default because of buggy wasapi plugin. GstRegistry *reg = gst_registry_get(); if (reg) { GstPluginFeature *directsoundsink = gst_registry_lookup_feature(reg, "directsoundsink"); GstPluginFeature *wasapisink = gst_registry_lookup_feature(reg, "wasapisink"); if (directsoundsink && wasapisink) { gst_plugin_feature_set_rank(directsoundsink, GST_RANK_PRIMARY); gst_plugin_feature_set_rank(wasapisink, GST_RANK_SECONDARY); } if (directsoundsink) gst_object_unref(directsoundsink); if (wasapisink) gst_object_unref(wasapisink); } #endif
-
Nice !!
Thanks for sharing your discovery !