I am currently trying to unzip a .cbz file (basically a .zip file) and store all of the .png images contained in that .cbz file to a std::vector<QImage>
.
I am using QuaZip to do this. I've looked at a few examples online and have tried implementing a few different methods using QuaZip classes documentation.
This is the code that I currently have:
// Store all files for later access given the CBZ file
bool CbzReader::loadCbzFile(QString cbzFile) {
QuaZip zip(cbzFile);
zip.open(QuaZip::mdUnzip);
const QStringList fileList = zip.getFileNamesList();
QStringList allFiles = JlCompress::extractFiles(cbzFile, fileList);
QImage newImage;
for(int file = 0; file < fileList.size(); file++) {
QImageReader reader(allFiles[file]);
newImage = reader.read();
if(newImage.isNull()) return false;
imageList.push_back(newImage); //save image to class variable
}
return true;
}
The variable allFiles
contains 265 entries, however, inside of the for loop, it is returning false
, as the newImage
is said to be invalid
by Qt.
What about this am I doing incorrectly? Should I use different functions within QuaZip instead of JlCompress?
It turns out that extracting the .cbz file resulted in at least one file that was not an image file, and a QImage was attempting to be made out of this, causing an error. I was not paying close enough attention to the contents of the unzipped file.
This now works since I'm using a boolean expression to check the file extensions of the uncompressed files.
So yeahhhh, my bad guys.