I was surprised that the following code (which I'm working on for the applix filter) ...
paragraphBuffer.close(); bodyWriter->startElement("text:p"); bodyWriter->addAttribute("text:style-name", autoStyleName); bodyWriter->addCompleteElement(¶graphBuffer); bodyWriter->endElement(); // text:p paragraphBuffer.setData(QByteArray()); ... would fail in QBuffer::setData with "can't do that while the buffer is open". Turns out that addCompleteElement opens the iodevice, but doesn't close it afterwards -- blame me, I wrote that code long ago ;) Can I commit the attached patch? I had a look at the existing callers of addCompleteElement (some of them -- there are many many more than I thought there would be!), and it seems to be always a one-time buffer. And if it was reused, then a second close() won't hurt. -- David Faure, fa...@kde.org, http://www.davidfaure.fr Sponsored by Nokia to work on KDE, incl. Konqueror (http://www.konqueror.org).
diff --git a/libs/odf/KoXmlWriter.cpp b/libs/odf/KoXmlWriter.cpp index b2ec8a4..bcb205e 100644 --- a/libs/odf/KoXmlWriter.cpp +++ b/libs/odf/KoXmlWriter.cpp @@ -147,10 +147,13 @@ void KoXmlWriter::addCompleteElement(const char* cstr) void KoXmlWriter::addCompleteElement(QIODevice* indev) { prepareForChild(); - bool openOk = indev->open(QIODevice::ReadOnly); - Q_ASSERT(openOk); - if (!openOk) - return; + const bool needOpen = !indev->isOpen(); + if (needOpen) { + const bool openOk = indev->open(QIODevice::ReadOnly); + Q_ASSERT(openOk); + if (!openOk) + return; + } static const int MAX_CHUNK_SIZE = 8 * 1024; // 8 KB QByteArray buffer; buffer.resize(MAX_CHUNK_SIZE); @@ -160,6 +163,9 @@ void KoXmlWriter::addCompleteElement(QIODevice* indev) break; d->dev->write(buffer.data(), len); } + if (needOpen) { + indev->close(); + } } void KoXmlWriter::endElement()
_______________________________________________ calligra-devel mailing list calligra-devel@kde.org https://mail.kde.org/mailman/listinfo/calligra-devel