c++ - 将 QuaZip 添加到项目中

标签 c++ qt qt5 qt-creator

我正在尝试将 QuaZip 添加到我的项目中,但出现构建错误,所有这些都与 undefined reference 有关。 这是第一个错误,它们主要与 extractAll 函数中的存档函数有关。

错误:对 `_imp___ZN6QuaZip13goToFirstFileEv' 的 undefined reference

这是对我的 .pro 文件的补充:

INCLUDEPATH += $$PWD/quazip/
LIBS += -L$$PWD/libs/

INCLUDEPATH += $$PWD/zlib/include/
INCLUDEPATH += $$PWD/zlib/lib/
LIBS += -L$$PWD/zlib/lib/

在 quazip 子文件夹中,我有 quazip 的所有标题。 在那之后的行中,在 libs 文件夹中,我有 .a 用于 quazip。 zilib 子文件夹包含 zlib 开发人员文件。

这是我尝试使用的函数:

void Utilities::updateFiles_zip()
{
    currentDownloads.clear();
    init_files();

    QString error = "";
    QString file = "LAE-Intnl-numbers-new.zip";

    error = checkForUpdates(file);

    if (error != "")
    {
        errorMessage = error;
        if (DEBUG)
            qDebug() << "error = {" <<  error << "}";       
        return; 
    }

    QString filename = downloadPath + "LAE-Intnl-numbers-new.zip";
    QuaZip *zip_file = new QuaZip(filename);
    extractAll(zip_file, inputPath);
}


void Utilities::extractAll( QuaZip *archive, QString destFileFolder )
{
    // extracts all files from the archive and saves
    // them onto disk
    //
    // just a simple implementation for evaluation.
    // error handling has not been implemented yet!

    for( bool f = archive->goToFirstFile(); f; f = archive->goToNextFile() )
    {
        // set source file in archive
        QString filePath = archive->getCurrentFileName();
        QuaZipFile zFile( archive->getZipName(), filePath );
        // open the source file
        zFile.open( QIODevice::ReadOnly );
        // create a bytes array and write the file data into it
        QByteArray ba = zFile.readAll();
        // close the source file
        zFile.close();
        // set destination file
        QString destFilePath = destFileFolder +  filePath;
        QFile dstFile( destFilePath );
        // open the destination file
        dstFile.open( QIODevice::WriteOnly | QIODevice::Text );
        // write the data from the bytes array into the destination file
        dstFile.write( ba.data() );
        //close the destination file
        dstFile.close();
    }
}

编辑:让它符合要求,但应用程序现在崩溃了。

这是我的 .pro 文件的样子:

#-------------------------------------------------
#
# Project created by QtCreator 2013-04-20T05:16:50
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Lottery
TEMPLATE = app

INCLUDEPATH += $$PWD/zlib/include
INCLUDEPATH += $$PWD/zlib/lib
LIBS += -L$$PWD/zlib/lib

LIBS += -L$$PWD/libs/ -lquazip

SOURCES += main.cpp \
        mainwindow.cpp \
        Games.cpp \
        Config.cpp \
        ProcessNumbers.cpp \
        SortMethods.cpp \
        Headers.cpp \
        AnalysisMethods.cpp \
        CombosMethods.cpp \
        CheckMatchesMethods.cpp \
        MatchesMethods.cpp \
        RandomMethods.cpp \
        form.cpp \
        Utilities.cpp \
        numbersranksavgsdiffs.cpp \
        MatchesMethods_LM.cpp



HEADERS  += mainwindow.h \
    AnalysisMethods.h \
    Config.h \
    Headers.h \
    ProcessNumbers.h \
    SortMethods.h \
    dates.h \
    sorts.h \
    update.h \
    Games.h \
    CombosMethods.h \
    combos.h \
    gameballs.h \
    comboscheck.h \
    CheckMatchesMethods.h \
    MatchesMethods.h \
    RandomMethods.h \
    checkmatches.h \
    progress.h \
    form2.h \
    matches.h \
    random.h \
    Utilities.h \
    pointers.h \
    diffs.h \
    numbersranksavgsdiffs.h \
    MatchesMethods_LM.h \
    matches_lm.h \
    analysis.h

include(quazip.pri)


FORMS    += \
    mainwindow.ui \
    dates.ui \
    update.ui \
    sorts.ui \
    combos.ui \
    gameballs.ui \
    comboscheck.ui \
    checkmatches.ui \
    form2.ui \
    progress.ui \
    matches.ui \
    random.ui \
    diffs.ui \
    matches_lm.ui \
    analysis.ui

QT += network

QT += core gui widgets

QT += concurrent

#QMAKE_LFLAGS_WINDOWS += -Wl,--stack,32000000

#QMAKE_LFLAGS += /STACK:32000000

#QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01

RC_ICONS = currency_blue_dollar.ico

这是我的 quazip.pri 外观:

#INCLUDEPATH += $$PWD/quazip
#DEPENDPATH += $$PWD/quazip

INCLUDEPATH += $$PWD/quazip/headers


HEADERS += $$PWD/quazip/headers/minizip_crypt.h \
        $$PWD/quazip/headers/ioapi.h \
        $$PWD/quazip/headers/JlCompress.h \
        $$PWD/quazip/headers/quaadler32.h \
        $$PWD/quazip/headers/quachecksum32.h \
        $$PWD/quazip/headers/quacrc32.h \
        $$PWD/quazip/headers/quagzipfile.h \
        $$PWD/quazip/headers/quaziodevice.h \
        $$PWD/quazip/headers/quazipdir.h \
        $$PWD/quazip/headers/quazipfile.h \
        $$PWD/quazip/headers/quazipfileinfo.h \
        $$PWD/quazip/headers/quazip_global.h \
        $$PWD/quazip/headers/quazip.h \
        $$PWD/quazip/headers/quazipnewinfo.h \
        $$PWD/quazip/headers/unzip.h \
        $$PWD/quazip/headers/zip.h
#        $$PWD/zlib/include/zlib.h

#SOURCES += $$PWD/quazip/qioapi.cpp \
#           $$PWD/quazip/JlCompress.cpp \
#           $$PWD/quazip/quaadler32.cpp \
#           $$PWD/quazip/quacrc32.cpp \
#           $$PWD/quazip/quagzipfile.cpp \
#           $$PWD/quazip/quaziodevice.cpp \
#           $$PWD/quazip/quazip.cpp \
#           $$PWD/quazip/quazipdir.cpp \
#           $$PWD/quazip/quazipfile.cpp \
#           $$PWD/quazip/quazipfileinfo.cpp \
#           $$PWD/quazip/quazipnewinfo.cpp \
#           $$PWD/quazip/unzip.c \
#           $$PWD/quazip/zip.c

最佳答案

为什么不将源代码放在您喜欢的任何目录中。例如,第 3 方:

|-- project.pro
|-- ....
|-- 3rdparty\
|     |-- QuaZip\
|     |

将以下行添加到您的 qmake 项目文件中:

include(3rdparty/quazip/blob/master/quazip.pri)

qmake将完​​成这项工作

关于c++ - 将 QuaZip 添加到项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57354057/

相关文章:

python - PyQt 自定义小部件未显示

c++ - QPushButton c++ 的动态 QGridLayout

c++ - QDialog不在 parent 的中心

c++ - WinINet 无法将文件下载到客户端?

c++ - 我应该怎么做才能在 Visual Studio 2013 中为我的 C++ 项目使用 boost 库

c++ - 使用 libcurl 和 Fiddler 拦截 HTTPS 流量

c++ - 确定在 Qt 中按下了哪个快捷方式

c++ - 使用带有 std::shared_ptr 的 Qt 对象

opencv - 如何在 Qt Resorce 文件中添加 Opencv XML 文件或将其包含在 exe 文件中?

c++ - 在 C++ 基类构造函数中注入(inject)代码