PDA

View Full Version : QuaZip/QSaveFile interaction issue



zaphod.b
25th October 2013, 15:56
Hi all,

I use QuaZip (http://quazip.sourceforge.net) to process ZIP archives. Eventually I have to write new archives to disc, and make absolutely sure of success before I proceed. As I understand, from Qt 5.1, QSaveFile (http://qt-project.org/doc/qt-5.1/qtcore/qsavefile.html) is intended to accomplish this. This stackoverflow post (http://stackoverflow.com/questions/19096702/qfileflush-vs-qfileclose#comment28234944_19097368) suggests that QSaveFile indeed implicitly ensures the file is synced to disc.

Now, though I do question some of QSaveFile's design decisions, this post is about pragmatic solutions.

I am looking for a way - with as little effort as possible ;) - to safely write a QuaZip to disc. QuaZip does provide a ctor that takes a QIODevice. However, as the QuaZip::close() docs (http://quazip.sourceforge.net/classQuaZip.html#a7a4323b73e12f3b4470109f200728f9f ) state:

The underlying QIODevice is also closed, regardless of whether it was set explicitly or not.
QSaveFile not only overrides access to close() as private, but also does this:

/*!
\reimp
Cannot be called.
Call commit() instead.
*/
void QSaveFile::close()
{
qFatal("QSaveFile::close called");
}

which crashes my appplication when QuaZip::close() implicitly calls QIODevice::close() on the QSaveFile.

Any suggestions appreciated.