qt5中字符串转字符串数组_如何在Qt 5.3中将QByteArray转换为字符串?

在Qt 5.3中,由于QByteArray是无类型的,当试图用它来初始化QString时,可能会得到空字符串。问题在于QString尝试将字节数组解释为字符串数据。要显示QByteArray中的double数据,可以使用类似反序列化的方法,通过QDataStream将其转换回原始数据类型。
摘要由CSDN通过智能技术生成

I am using some functions to convert QVector's to QByteArray's, for example:

QByteArray Serialize::serialize(QVector data)

{

QByteArray byteArray;

QDataStream out(&byteArray, QIODevice::WriteOnly);

out << data;

return byteArray;

}

void Serialize::deserialize(QByteArray byteArray, QVector *data)

{

QDataStream in(&byteArray, QIODevice::ReadOnly);

in >> *data;

}

Now, that I have the QByteArray I need to put it in a text file, how can I convert it to QString?

I already tried the simplest way:

QString myString(data); // data - QByteArray

But myString is always empty.

I also found the toStdString() function in the documentation, but it was introduced only in Qt 5.4.

I'm using Qt 5.3.

Follows a com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值