I am trying to use a simple drag and drop function in my Qt application. Here is my code:
MyWindow::MyWindow(QWidget *parent) { .......... setAcceptDrops(true); } void MyWindow::dragEnterEvent(QDragEnterEvent *e) { if (e->mimeData()->hasUrls()) { e->acceptProposedAction(); } } void MyWindow::dropEvent(QDropEvent *e) { foreach (const QUrl &url, e->mimeData()->urls()) { const QString &fileName = url.toLocalFile(); qDebug() << "Dropped file:" << fileName; } }
As you can see, it just prints the path name of the file being dropped to the console. Therefore, when I dragged a file from the desktop to the widget, I expected something like /Users/<myName>/Desktop/<filename>
in the console. But I see something like file:///.file/id=6571367.2773272/
. And when I try to use it in some way, for example, to open a file (text) in my built-in editor, which works fine for all OSs except Os X Yosemite , the application crashes.
This is a known bug posted here with the patch here . But I do not know how to use the patch to make my code work. There seems to be a solution with Objective-C wrapping around Qt, however I don't know how to mix C ++ in Qt and Objective-C exactly.
Any idea how I can use the patch or make it work in some other way? Somehow I need to restore the actual full path to the file to be deleted.
Environment - Os X Yosemite, Qt Creator 3.1.1 with Qt 5.2.1.
I also need to run the same application on Windows (we are developing Qt for Windows and Mac), so we are looking for a cross-platform solution.
source share