Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qml下载二进制文件 #40

Open
myml opened this issue Jun 28, 2023 · 0 comments
Open

qml下载二进制文件 #40

myml opened this issue Jun 28, 2023 · 0 comments

Comments

@myml
Copy link
Owner

myml commented Jun 28, 2023

在 qml 中可以使用XMLHttpRequest发送网络请求并获取返回内容,XMLHttpRequest 有个 responseType 属性, QT 文档中是这样说的:

responseType : string
Returns a String describing the content type of the last response received.

If the response type is "text" or an empty String, the response content is a UTF-16 encoded String.
If the response type is "arraybuffer", it means that the response content is an ArrayBuffer containing binary data.
If the response type is "json", the response content should be a JSON Document.
If the response type is "document", it means that the response content is an XML Document, which can be safely read with the responseXML property.

就我理解是先获取 responseType 的值,然后再按不同的类型读取 response ,实际上 response 的值是空的,需要手动设置 responseType ,response 才会更改为对应的类型。

如果想使用XMLHttpRequest获取二进制数据,比如图片文件,需要设置 responseType = "arraybuffer" , response 的值才会是 ArrayBuffer 类型,该类型传递给 Qt 会自动转换为 QByteArray 类型,如果不设置 responseType,response 默认是string类型,传递给 Qt 时,使用 QByteArray 类型接收并不会报错,但数据是无效的无法使用。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant