qt - 无法分配 QList到 QString
问题描述
我遇到了这个错误:
Unable to assign QList<QUrl> to QString
当尝试将(从的处理程序获得)的结果直接分配给Python中的标签属性时。drop.urls
DropArea
onDropped
text
基于this doc,我尝试Qt.resolvedUrl
(将类型转换为字符串),如下面的代码所示。但是,它会导致一个空的文本标签。我正在使用的网址以“ file:/// ”开头。
我究竟做错了什么?
import QtQuick.Window 2.2
import QtQuick 2.2
import QtQuick.Controls 2.14
Window {
id: root
visible: true
width: 640
height: 480
title: "Drop Test"
property var attachments: "empty"
DropArea {
id: dropArea;
anchors.fill: parent
onEntered: {
root.color = "gray";
console.log("You entered drop area")
drag.accept (Qt.LinkAction);
}
onDropped: {
console.log("You dropped " + drop.urls)
attachments = Qt.resolvedUrl(drop.urls)
}
}
Label {
id: mLableId
text: attachments
}
}
将 URL 分配给字符串似乎是一个显而易见的问题,但如果它已经在 Python 和 Qt Quick 的上下文中被问过,我从昨天开始搜索后还没有找到任何这样的现有问题。
解决方案
urls 是一个 url 列表,因此您必须迭代和连接:
onDropped: {
console.log("You dropped " + drop.urls)
var str = ""
for(var i in drop.urls){
var url = drop.urls[i]
str += Qt.resolvedUrl(url)
}
attachments = str
}
推荐阅读
- python - 如何在水平 Seaborn 条形图上注释文本?
- c# - MvxObservableCollection 不更新 UI
- python - Django 3 ASGI 和 Django 2 + Channels 有什么不同?
- mysql - 存储引擎大小以及行数和列数
- javascript - 在 tsc TypeScript 编译中包含 CSS 文件
- c# - 检查数组内所有元素的条件是否为真
- jquery - 从 azure 发布和接收
- binary - GraphQL 中的二进制
- javascript - 在前端接收 JSON 字符串格式的响应是否理想?
- ios - Sqlite 在表中插入值不能在 swift 中正常工作