I was trying to use a simple drag and drop feature in my Qt app. 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 see, it simply prints the path name of the file bing dropped into the console. So when I dragged and dropped a file from my desktop into the widget, I expected something like /Users/<myName>/Desktop/<filename>
in the console. But I see something like file:///.file/id=6571367.2773272/
being printed. And when I try to use it in some way, like opening the file (text) in my in-built editor, which was working fine for all OS-es except Os X Yosemite, the app crashes.
It is a known bug, as published here, with a patch here. But I don't know how to use the patch to make my code work. There seems to be a solution with an Objective C wrapper around Qt, however, I don't know how exactly to mix C++ in Qt and Objective C.
Any idea how do I use the patch, or make it work in some other way? Somehow I need to retrieve the actual full path of the file being dropped.
Environment - Os X Yosemite, Qt Creator 3.1.1 with Qt 5.2.1.
I will need to run the same app on Windows as well (we are developing in Qt for both Windows and Mac), so looking for cross-platform solution.
Right, this a generic
request. This may be useful to document in general, therefore here goes the answer.
You could grab the official release tarball and patch that without git or you can go through the repository. I would personally opt for the second since patching and cherry-picking with git is easier in my humble opinion. These are the steps that you need to take:
Clone the Qt 5 repository
Go to the cloned directory
Initialize the repository
Go to the qtbase directory which you need to patch
Create a gerrit account if you have none yet. This step is optional.
a. Fetch and cherry-pick the fix from Gerrit
b. Do not create a gerrit account
This will be feasible in this case since it is a very minor change to the source code, and all the rest is just change to the benchmarks. There are no expected updates to the craft of the change, either.
Configure the project
Build and install the project
Go get some tea until it is ready
To apply the patch, you would need to download the Qt Sources (ex. use git) and then add the lines needed to retrieve the filepath instead of the fileId using the:
method.
Here is the part where it should be added: Patch Code
When you did this, you need to build Qt and build your project with this patched version to take use of the changes you made.