Reputation: 1176
I implemented a drag and drop functionality in an Qt application (In case you want to see some code, see below). I thought everything is working fine until a user told me that it is not working for him.
Usually you see this icon, if
dragEnterEvent()
does not call event->acceptProposedAction()
, then you see this icon. And if the issue occurs you see an icon similar to this
(It's not exactly that icon, but I am not able to capture it, as windows removes the mouse icon in screenshots).
We could find out that on some computers (not for me sadly, so debugging that is quite hard) it depends on the setup. In particular the installation path: If the application lies in one specific directory (or one of its subdirectories) the described error occurs. If we move the whole application directory somewhere else and execute it from there, everything works fine.
Adding some debug output showed that the dragEnterEvent() does not fire in the broken setup.
What could be the reason? How can I debug that issue?
We had some suspicions but nothing that realy makes sense. But I want to share them anyway:
Code snippet:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
/* more here */
{
/* more here */
setAcceptDrops(true);
/* more here */
}
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
{
const QMimeData* mimeData = event->mimeData();
if (mimeData->hasUrls()) {
QString fileName = mimeData->urls().at(0).toLocalFile();
QFileInfo file(fileName);
if(isSupportedFileType(file.completeSuffix())) {
event->acceptProposedAction();
}
}
}
void MainWindow::dropEvent(QDropEvent *event)
{
const QMimeData* mimeData = event->mimeData();
if (mimeData->hasUrls()) {
QList<QUrl> urlList = mimeData->urls();
if(openFiles(urlList)) {
event->acceptProposedAction();
}
}
}
Upvotes: 3
Views: 1810
Reputation: 941505
There is one scenario where D+D seems to fail for no discernible reason. Easy to repro on your machine, right-click the shortcut for your app and select "Run as Administrator".
UIPI forbids dragging from a non-elevated app into an elevated one. No loud feedback, your app simply doesn't get any of the D+D events. Interview your user about this, you'll want to know if he has a need to elevate your app. Having your installer automatically start your app will misbehave the same way.
Upvotes: 4