Qt 5.5 project build error in Qt 5.8

本小妞迷上赌 提交于 2020-01-11 13:51:07

问题


I was developing a simple application on Qt 5.5. Since Qt 5.5 does not have QChart class features, I had to install and build my Qt 5.5 project on the 5.8 distribution. For my project I am using this 3rd party software called the QXlsx to create and edit Excel spreadsheets. This library was working flawlessly in Qt 5.5 but fails to compile on the Qt 5.8 version. The compilation returns the following error;

/Users/Vino/Documents/My Stuff/Qt Projects/Fundemental Analysis/FundementalAnalysis/3rdparty/qtxlsx/src/xlsx/xlsxzipreader.cpp:52: error: implicit instantiation of undefined template 'QVector<QZipReader::FileInfo>' QList<QZipReader::FileInfo> allFiles = m_reader->fileInfoList(); ^ I am not sure what it means, but I am quite confident that I don't have to make any changes on the source code of this library since it worked previously on Qt 5.5.

Anyway this is the source code where the error occurs

#include "xlsxzipreader_p.h"
#include <private/qzipreader_p.h>



namespace QXlsx {

    ZipReader::ZipReader(const QString &filePath) :
    m_reader(new QZipReader(filePath))
    {
         init();
    }

    ZipReader::ZipReader(QIODevice *device) :
    m_reader(new QZipReader(device))
    {
         init();
    }

    ZipReader::~ZipReader()
    {

    }

    void ZipReader::init()
    {
           QList<QZipReader::FileInfo> allFiles = m_reader->fileInfoList();
           foreach (const QZipReader::FileInfo &fi, allFiles) {
           if (fi.isFile)
                 m_filePaths.append(fi.filePath);
    }
}

     bool ZipReader::exists() const
     {
           return m_reader->exists();
     }

    QStringList ZipReader::filePaths() const
    {
       return m_filePaths;
    }

    QByteArray ZipReader::fileData(const QString &fileName) const
    {
         return m_reader->fileData(fileName);
    }
}// namespace Xlsx

The error occurs at this function;

    void ZipReader::init()
    {
         QList<QZipReader::FileInfo> allFiles = m_reader->fileInfoList();
         foreach (const QZipReader::FileInfo &fi, allFiles) 
         {
              if (fi.isFile)
              m_filePaths.append(fi.filePath);
         }
    }

So as a solution I tried adding #include <QList> to the source code since QList is referenced with specifying the header but this does not resolve the issue. When I added #include <QList>, a new myriad of errors popped up. How can I build this project?


回答1:


the error for QtXLSX has not been solved.

The solution is simple.

On the file xlsxzipreader.cpp, it is necesary to include:

#include <QVector>

After that in the function: void ZipReader::init(){}, we need to update the type:

void ZipReader::init(){
// This was the previous definition
//QList<QZipReader::FileInfo> allFiles = m_reader->fileInfoList();

QVector<QZipReader::FileInfo> allFiles = m_reader->fileInfoList();

foreach (const QZipReader::FileInfo &fi, allFiles) {
    if (fi.isFile)
        m_filePaths.append(fi.filePath);
    }
}

Just save and do again:

make
make install

This has been tested on Qt 5.8.x, 5.9.x

Cheers!




回答2:


So I fixed my problem; I was using the oldest version of the QXlsx, and according to this post, there were many new revisions on gitHub. Installing the new version solved the issue.

New version
Old version



来源:https://stackoverflow.com/questions/42353619/qt-5-5-project-build-error-in-qt-5-8

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!