Sex*_*ast 6 c++ qt drag-and-drop osx-yosemite
我试图在我的Qt应用程序中使用简单的拖放功能.这是我的代码:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,它只是打印放入控制台的文件的路径名.因此,当我将一个文件从我的桌面拖放到小部件中时,我期望/Users/<myName>/Desktop/<filename>在控制台中有类似的东西.但我看到像file:///.file/id=6571367.2773272/被打印的东西.当我尝试以某种方式使用它时,比如在我的内置编辑器中打开文件(文本),这对于除Os X Yosemite之外的所有操作系统都很好,应用程序崩溃了.
这是一个已知的bug,公布在这里,有一个补丁在这里.但我不知道如何使用补丁来使我的代码工作.似乎有一个围绕Qt的Objective C包装器的解决方案,但是,我不知道如何在Qt和Objective C中混合使用C++.
我知道如何使用补丁,或以其他方式使其工作?不知何故,我需要检索被删除文件的实际完整路径.
环境 - Os X Yosemite,Qt Creator 3.1.1,Qt 5.2.1.
我还需要在Windows上运行相同的应用程序(我们正在为Windows和Mac开发Qt),因此寻找跨平台解决方案.
没错,这是一个通用的
如何修补 Qt 源代码以修复错误或添加功能?
要求。这对于一般记录可能很有用,因此答案如下。
您可以获取官方发布的 tarball 并在没有 git 的情况下修补它,或者您可以浏览存储库。我个人会选择第二种,因为在我看来,使用 git 进行修补和挑选更容易。您需要执行以下步骤:
克隆 Qt 5 存储库
git clone git://gitorious.org/qt/qt5.git qt5
Run Code Online (Sandbox Code Playgroud)进入克隆的目录
cd qt5
Run Code Online (Sandbox Code Playgroud)初始化存储库
perl init-repository
Run Code Online (Sandbox Code Playgroud)进入需要打补丁的qtbase目录
cd qtbase
Run Code Online (Sandbox Code Playgroud)如果您还没有 gerrit 帐户,请创建一个。此步骤是可选的。
A。从 Gerrit 获取并挑选修复程序

git fetch https://yourgerritusername@codereview.qt-project.org/qt/qtbase refs/changes/11/92611/4 && git cherry-pick FETCH_HEAD
Run Code Online (Sandbox Code Playgroud)
b. 不要创建 gerrit 帐户
在这种情况下这是可行的,因为这只是对源代码的一个非常小的更改,其余的只是对基准的更改。变革的技术也没有预期的更新。
* git apply
* copy and paste the following snippet to the standard input
commit 66a305f282e33b1bf12bec21f416c8ba6730cd40
Author: Cyril Oblikov <munknex@gmail.com>
Date: Tue Aug 19 16:18:25 2014 +0300
OSX: convert file reference url to path-based url
According to Apple's spec URL can be:
path-based URL: file://localhost/Users/steve/Documents/MyFile.txt
or
file reference URL: file:///.file/id=6571367.2773272/
On OSX 10.10 file reference urls are copied to clipboard during Drag&Drop.
This patch converts file reference url to path-based url.
Comment on performance: converting 1000 urls on Macbook Air 2013 takes
about 15 ms.
Also benchmark is added.
Change-Id: Ia42386cd90d1eb11d04ab33705f5eece6c13f370
diff --git a/src/platformsupport/clipboard/qmacmime.mm b/src/platformsupport/clipboard/qmacmime.mm
index 6fcd19e..2bb623f 100644
--- a/src/platformsupport/clipboard/qmacmime.mm
+++ b/src/platformsupport/clipboard/qmacmime.mm
@@ -614,6 +614,8 @@ QVariant QMacPasteboardMimeFileUri::convertToMime(const QString &mime, QList<QBy
QUrl url = QUrl::fromEncoded(data.at(i));
if (url.host().toLower() == QLatin1String("localhost"))
url.setHost(QString());
+ if (url.host().isEmpty() && url.path().startsWith(QLatin1String("/.file/id=")))
+ url = QUrl::fromNSURL([url.toNSURL() filePathURL]);
url.setPath(url.path().normalized(QString::NormalizationForm_C));
ret.append(url);
}
Run Code Online (Sandbox Code Playgroud)
配置项目
./configure -developer-build -opensource -nomake examples -nomake tests
Run Code Online (Sandbox Code Playgroud)构建并安装项目
make -j4 all install
Run Code Online (Sandbox Code Playgroud)去喝点茶直到茶准备好