Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

qUncompress Z_DATA_ERROR error



  • Hello,

    I am facing an issue which I cannot solve when I uncompress data with qUncompress. I need to open an XML file to be read by a QDomDocument.

    When tesing this, it works perfectly.

                QFile f1(filePath);
                f1.open(QIODevice::ReadOnly | QIODevice::Text);
                QByteArray b1 = f1.readAll();
                QByteArray b2 = qCompress(b1);
                QByteArray b3 = qUncompress(b2);
                document.setContent(b3);
    

    When doing the same through a QFile, it fails with error "qUncompress: Z_DATA_ERROR: Input data is corrupted"

                QFile f1(filePath);
                f1.open(QIODevice::ReadOnly | QIODevice::Text);
                QByteArray b1 = f1.readAll();
                QByteArray b2 = qCompress(b1);
    
                QFile f2(filePath + "c");
                f2.open(QIODevice::WriteOnly | QIODevice::Text);
                f2.write(b2);
    
                QFile f3(filePath + "c");
                f3.open(QIODevice::ReadOnly | QIODevice::Text);
                QByteArray b3 = qUncompress(f3.readAll());
                document.setContent(b3);
    

    I really do not understand the difference in terms of compression/decompression. Any idea ? Thanks !!



  • Sorry for this post, I found my mistake : remove "QIODevice::Text" in file open arguments...


Log in to reply