Qt读zip文件

#include <QtCore/QCoreApplication>
#include <QTextStream>
#include <QXmlStreamReader>
#include <QtXML/QDom.h>
#include <QZip/QuaZipFile.h>
#include <iostream>

int main(int argc,char *argv[])
{
    QCoreApplication app(argc,argv);
    QuaZip zip(":qrc/zip.zip");
    if(!zip.open(QuaZip::mdUnzip))
    {
        std::cout<<"open failed:"<<zip.getZipError()<<std::endl;
        system("pause");
        return -1;
    }

    if(zip.setCurrentFile("list.xml"))
    {
        QuaZipFile zipfile(&zip);
        if(!zipfile.open(QIODevice::ReadOnly))
        {
            std::cout<<"open zipfile failed"<<std::endl;
            system("pause");
            return -1;
        }

        QTextStream stream(&zipfile);
        while(!stream.atEnd())
            std::cout<<qPrintable(stream.readLine())<<std::endl;

        zipfile.close();
        zip.close();
    }
    else
        std::cout<<"set current file failed."<<std::endl;
    system("pause");
    return 1;
}

需要使用QuaZip库

庄朋龙
庄朋龙

一个爱生活的技术菜鸟

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注