QDataStream 序列化指针地址需要注意以下几点:

  1. 需要使用指针类型的变量来保存指针地址,如 uint64_t 或 qintptr;
  2. 在序列化时,需要将指针地址转换为整型,如使用 qintptr(ptr);
  3. 在反序列化时,需要将整型转换回指针地址,如使用 reinterpret_cast<T*>(ptr)。

示例代码:

// 序列化
QDataStream stream(&byteArray, QIODevice::WriteOnly);
uint64_t ptrValue = reinterpret_cast<uint64_t>(ptr); // 将指针地址转换为整型
stream << ptrValue;

// 反序列化
QDataStream stream(&byteArray, QIODevice::ReadOnly);
uint64_t ptrValue;
stream >> ptrValue;
T* ptr = reinterpret_cast<T*>(ptrValue); // 将整型转换回指针地址
qdatastream 序列化 指针地址

原文地址: https://www.cveoy.top/t/topic/W03 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录