php - 如何在 QT/C++ 中解压缩在 PHP 中压缩的数据 (gzcompres)

标签 php c++ qt

我有一个用 PHP gzcompress($string) 写的压缩字符串

我需要在 QT 上用 C++ 阅读它。

非常感谢任何帮助!

最佳答案

您可以使用 qUncompress:http://doc.trolltech.com/4.6/qbytearray.html#qUncompress
请注意,您需要预先添加预期的未压缩长度。

示例代码(C++):

QByteArray aInCompBytes;
QByteArray aInUnCompBytes;
QByteArray aInCompBytesPlusLen;

int currentCompressedLen = <<read_this>>;
int currentUnCompressedLen = <<read_this>>;

aInCompBytes.resize(currentCompressedLen);

char slideStr[currentCompressedLen];
int slideByteRead = in.readRawData(slideStr, currentCompressedLen);

aInCompBytes = QByteArray(slideStr, slideByteRead);
aInCompBytesPlusLen = aInCompBytes;
aInCompBytesPlusLen.prepend(QByteArray::number(currentUnCompressedLen));
aInUnCompBytes.resize(currentUnCompressedLen);
aInUnCompBytes = qUncompress(aInCompBytesPlusLen);

未压缩的数据将在 aInUnCompBytes 中。 您需要阅读/了解压缩的 len 和未压缩的 len。 它没有经过测试,因为我现在的机器上没有 Qt。

最好的问候,

关于php - 如何在 QT/C++ 中解压缩在 PHP 中压缩的数据 (gzcompres),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2654030/

相关文章:

php - mysql - 子查询和连接

php - ¿如何复制 session ?

xcode - 让 QMake 生成正确的 .app

c++ - 为什么官方的 Qt 示例和教程不使用智能指针?

javascript - 在 JavaScript 中单击按钮时下载按钮和输入字段没有响应

php - 对于我的一生,我不知道如何设置 Zend Framework

c++ - DLIB:具有 halen 数据集的 194 个地标的 train_shape_predictor_ex.exe 给出运行时错误:错误分配

由 小码哥发布于 2019-11-08 09:00:00 c++design: avoid iterating over types with an existing class hierarchy

c++ - C++ 中 Thread.SetApartmentState 的等价物是什么?

c++ - 如何动态调整 QLabel/QVBoxLayout/QWidget 中使用的 QImage 的大小