用Qt序列化,不用Qt反序列化? [英] Serialize with Qt, deserialize without Qt?

查看:634
本文介绍了用Qt序列化,不用Qt反序列化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 QDataStream 序列化一个结构并通过UDP发送,

If I serialize a struct using QDataStream and send this via UDP,

然后可以反序列化它没有Qt吗?

is it possible to then deserialize it without Qt ?

推荐答案

如果要在不使用Qt库的情况下反序列化,则必须阅读Qt序列化格式,在此处中进行了简要描述,并自行编写反序列化代码。而且,由于这种格式可能会更改,因此您应该在序列化应用程序中使用 setVersion ,并坚持使用可以在接收器中为其实现反序列化代码的某个版本。

if you want to deserialize without using the Qt library, you would have to read the Qt serialization format which is described briefly here, and write the deserialization code yourself. And since this format is likely to change, you should use setVersion in the serializing application and stick into some version that you can implement deserialization code for it in the receiver.

我不建议这样做,因为这可能会花费很长时间,并且在对标准IEEE 754格式用于序列化浮点数或可能出现的错误是由设备之间的不同字节序引起的。

I don't recommend doing this, as it may take you long time, and you may run into a lot of errors when implementing deserialization for primitives such as the standard IEEE 754 format used in serializing float numbers or maybe errors that are caused by different endianness across devices, etc. . .

那么,为什么要重新发明轮子呢?如果您不想在接收器中使用Qt,则可以使用常见的序列化格式。例如,许多编程语言都广泛支持JSON,并且Qt支持 。如果您不喜欢JSON,可以选择很多数据序列化格式

So, why reinventing the wheel? if you don't want to use Qt in your receiver, you can use a common serialization format. JSON for instance is widely supported in many programming languages, and it is supported in Qt. If you don't like something about JSON there are lots of data serialization formats to choose from.

这篇关于用Qt序列化,不用Qt反序列化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆