- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我试图在我的 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;
}
}
如您所见,它只是打印 bing 放入控制台的文件的路径名。因此,当我将桌面上的文件拖放到小部件中时,我希望得到类似 /Users/<myName>/Desktop/<filename>
的结果。在控制台中。但我看到类似 file:///.file/id=6571367.2773272/
的东西 正在打印。当我尝试以某种方式使用它时,例如在我的内置编辑器中打开文件(文本),该编辑器适用于除 Os X Yosemite 之外的所有操作系统,应用程序崩溃了。
这是一个已知错误,已发布 here , 带有补丁 here .但是我不知道如何使用补丁来使我的代码工作。似乎有一个围绕 Qt 的 Objective C 包装器的解决方案,但是,我不知道如何在 Qt 和 Objective C 中混合使用 C++。
知道如何使用该补丁,或使其以其他方式工作吗?我需要以某种方式检索要删除的文件的实际完整路径。
环境 - Os X Yosemite,Qt Creator 3.1.1 和 Qt 5.2.1。
我也需要在 Windows 上运行相同的应用程序(我们在 Qt 中为 Windows 和 Mac 开发),因此寻找跨平台解决方案。
最佳答案
对,这是一个通用的
How do I patch the Qt source in order to fix a bug or add a feature?
要求。这可能对一般文档有用,因此这里给出了答案。
您可以获取官方发布的 tarball 并在没有 git 的情况下对其进行修补,或者您可以浏览存储库。我个人会选择第二种,因为在我看来,使用 git 进行修补和挑选更容易。这些是您需要采取的步骤:
克隆 Qt 5 存储库
git clone git://gitorious.org/qt/qt5.git qt5
进入克隆目录
cd qt5
初始化存储库
perl init-repository
进入需要打补丁的qtbase目录
cd qtbase
如果您还没有 gerrit 帐户,请创建一个。此步骤是可选的。
一个。从 Gerrit 获取并挑选修复程序
git fetch https://yourgerritusername@codereview.qt-project.org/qt/qtbase refs/changes/11/92611/4 && git cherry-pick FETCH_HEAD
不要创建 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);
}
配置项目
./configure -developer-build -opensource -nomake examples -nomake tests
构建并安装项目
make -j4 all install
去喝点茶,直到它准备好
关于c++ - Os X Yosemite Qt 拖放文件名错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27093697/
我在这里有一个我想要做的事情的例子:http://jsbin.com/OwoYAlEQ/1/edit 这是我的 HTML: person one person two person three per
我想知道是否有人知道是否有一个预先制定的解决方案:我在 ASP.net 网站上有一个列表,我希望用户能够通过拖放对列表进行重新排序。此外,我希望有第二个列表,用户可以将第一个列表中的项目拖到其中。 到
我想知道是否有人知道是否有一个预先制定的解决方案:我在 ASP.net 网站上有一个列表,我希望用户能够通过拖放对列表进行重新排序。此外,我希望有第二个列表,用户可以将第一个列表中的项目拖到其中。 到
我在我的 Web 应用程序中使用 Ajax ControlToolkit 中的 ModalPopupExtender。我将其 Drag 属性设置为 true,但是当我拖动弹出面板并将其放到新位置时,它
所以,基于this answer ,我有一组可以拖放并卡入到位的 div。唯一的问题是,可拖动的 div 具有不同的高度,我需要它们始终捕捉到目标的底部,而不是顶部。 您可以在this JsFiddl
我一直在使用 Bea 的解决方案 here一段时间后发现它非常有帮助。现在我遇到的问题是,当我将项目拖放到另一个 ListView 控件中或拖放到另一个 ListView 控件中,并且我想在拖动“期间
我试图在使用 QTreeWidget.setItemWidget() 重新父级(拖放)后将小部件放入 QTreeWidgetItem 但是,如果编译以下代码,结果是 QTreeWidgetItem 内
这是场景,我使用的是prototype和scriptaculous,但我相信jquery也会有同样的问题。我在相对定位的 div 中有一个可拖动图像的列表。问题是我无法将图像拖出父 div...好吧.
我正在使用一个普通(Bootstrap)表,我想在其中包含可排序的行。我正在使用 Angular CDK (DragDropModule) 来实现排序/排序。但是,当拖动行时,它会扭曲宽度,因为 cd
我正在尝试在我的 UICollectionView 中实现拖放机制,这与在快捷方式应用程序中重新排序快捷方式的组件非常相似。 截至目前,行为是当您开始拖动时,会留下一个透明的单元格 View ,而另一
我有以下 Jquery UI 拖放 jsfiddle https://jsfiddle.net/zoojsfiddle/ud96jdcp/ 具有
我希望创建一个基于网络的“公告板”,可以这么说,用户可以在其中创建/删除/拖放“图钉”,而不允许重叠“图钉”。 这是一个图表,应该有助于说明我正在尝试创建的内容: 'pins' 可能已创建双击;他们会
我是一名优秀的程序员,十分优秀!