简体   繁体   English

从C#Web服务将字节数组检索到Qt

[英]Retrieve byte array from c# webservice into Qt

I use webservice written in c# that exposes bytearray of audio file (mp3 file) that is stored in database (using entity framework). 我使用以C#编写的Web服务,该服务公开了存储在数据库中(使用实体框架)的音频文件(mp3文件)的字节数组。

When I retrieve it in c# and save it into file using File.WriteAllBytes() I can listen to audio (file's size is 10kB). 当我在c#中检索它并使用File.WriteAllBytes()将其保存到文件中时,我可以收听音频(文件大小为10kB)。

I need to do the same with Qt. 我需要对Qt做同样的事情。 I parse the xml and save audio byte array to QByteArray like this: 我解析xml并将音频字节数组保存为QByteArray,如下所示:

QByteArray bytes = readValue().toUtf8(); 

where readValue() is QStringRef and then I save it to file 其中readValue()是QStringRef,然后将其保存到文件

qint64 bytesWritten = file.write(bytes);

File hes 14kB then and I suppose that there is some format problem but not sure where. 然后使用文件hes 14kB,我想是有格式问题,但不确定在哪里。

I solved this problem. 我解决了这个问题。 In webservice I return byte array converter to hex string 在Web服务中,我将字节数组转换器返回到十六进制字符串

string hex = BitConverter.ToString(ba);
string hexString = hex.Replace("-", "");

then in Qt I parse data 然后在Qt中我解析数据

QByteArray bytes = QByteArray::fromHex(readValue().toString().toLatin1()));

and save it to file 并保存到文件

qint64 bytesWritten = file.write(bytes);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM