当前位置:网站首页>QT serialization qdatastream
QT serialization qdatastream
2022-07-28 14:51:00 【Love the west wind】
Communication data serialization of all platforms , Every language will encounter QT As a cross platform language , Comparison has also done a good job ;
QDataStream to glance at API , Meeting << ,>> Overloaded , You can format native data types , Such as QString int;
QDataStream::QDataStream(QIODevice * d)
template <typename T>
inline QDataStream & operator<<(QDataStream & s, const QList<T> & l)
template <typename T>
inline QDataStream & operator>>(QDataStream & s, QList<T> & l)Use samples :
write in :
QByteArray outBlock;
QDataStream sendout(&outBlock,QIODevice::WriteOnly);
int totalBytes = 30;
QString type = "name";
OffSetArray offset;
offset.pt1 =0.1;
offset.pt2 =0.2;
offset.pt3 =0.3;
offset.pt4 =0.4;
QByteArray data;//=offset;
data.append((char*)&offset,sizeof (OffSetArray));
sendout<<totalBytes<<uchar(0) <<type<<data; // read
int total ;
QString name = "";
QByteArray tmp;
sendout>>totalBytes>>name>>tmp;
OffSetArray *pTest = (OffSetArray*)tmp.data();
QString str = QString("%1,%2,%3,%4").arg(pTest->pt1).arg(pTest->pt2).arg(pTest->pt3).arg(pTest->pt4);
qDebug() << "pt --"<<str;Of course , It can be serialized directly , Structure , But it needs to be realized by yourself , I prefer to switch according to the type ;
边栏推荐
猜你喜欢

2022 melting welding and thermal cutting examination questions and online simulation examination

MQTT入门级简单介绍与使用

It's so hot that solar power can't take off? Hello, head

爆肝整理JVM十大模块知识点总结,不信你还不懂

围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育

58 sub station Anju, broker marketing management platform login interface encryption reverse

UI开发中所遇到的各种坑

2022低压电工考试题及答案

@DS('slave') 多数据源兼容事务问题解决方案

看了就会的 Rainbond 入门教程
随机推荐
FormData对象的使用, var formdata=new FormData()
Why is it reverse to convert from other formats to BMP
linux安装redis
[线程安全问题] 多线程到底可能会带来哪些风险?
分集技术简略
SwiftUI 4.0 的全新导航系统
SwiftUI 布局 —— 尺寸( 下 )
468 product planning and promotion plan (150 copies)
文件批量重命名工具Bulk Rename Utility
Pointers and arrays (7)
Core Data 是如何在 SQLite 中保存数据的
Node文件操作
Why can the anonymous functions of JQ access the methods inside
String转为long 类型报错原因:要转为long必须是int、double、float型[通俗易懂]
C # read INI file and key value pair operation
C language program: judging triangles
Hand in hand from 0 to a "Nuggets special attention" Google plug-in, 5000 words detailed vue3 responsive principle, the advantages, disadvantages and choices of several cache read-write schemes, flyin
Copy excel row to specified row
The method of implementing simple student achievement management system with C language
BGP experiment