Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Why my ODF (.odt) file is not generated correctly with QTextDocumentWriter ?
I'm trying de generate an ODF file using QTextDocumentWriter (as recommended) but it does not work properly. The same code is used to generate a PDF file and it works ! What's going wrong ? Can someone help me please ?
Here is my code :
int main(int argc, char *argv)
QApplication a(argc, argv);
QTextDocument * doc = new QTextDocument(); QTextCursor cursor(doc); QTextFrameFormat frameFormat; frameFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); cursor.movePosition(QTextCursor::NextBlock); cursor.insertFrame(frameFormat); QTextTable * table = cursor.insertTable(3,1); // Header cursor = table->cellAt(0, 0).firstCursorPosition(); cursor.insertText("File name"); // Image cursor = table->cellAt(1, 0).firstCursorPosition(); QImage image("/path/to/image/image.png", "png"); cursor.insertImage(image); // Footer cursor = table->cellAt(2, 0).firstCursorPosition(); QTextTable * table2 = cursor.insertTable(1, 2) ; // Author cursor = table2->cellAt(0, 0).firstCursorPosition(); cursor.insertText("Author"); // Date cursor = table2->cellAt(0, 1).firstCursorPosition(); cursor.insertText("17/10/2011"); // FORMAT PDF QPrinter printer(QPrinter::HighResolution); printer.setPageSize(QPrinter::A4); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName("rapport.pdf"); doc->print(&printer); // FORMAT ODF QTextDocumentWriter writer("rapport.odt"); writer.setFormat("odf"); writer.write(doc); return a.exec();
Can you explain "but it does not work properly" a bit more detailed? Is anything written at all? Is it data incomplete or corrupted?
First, thanks for replying. What i mean by "but it does not work properly" is :
- The second table in the posted code doesn't appear in the generated odf file. "author" & "17/10/2011" are missing.
- If i insert a second frame (from line 8 to line 29), there are not 2 pages as expected and as it is generated in the PDF file, but just one page.
Can you create a complete test case, the snippet does not compile (the cursor variable is undefined).
Complete test created (old posted code is edited) !
Nobody has an idea ?
Looks like a real bug - I have the same behavior on my Mac here.
I'd suggest you open an issue in the "public bugtracer":https://bugreports.qt.nokia.com/. Please report back the the bug ID here, so that others can follow and vote for it.
durgeshK last edited by
Any update on this issue? I am in desperate need to generate ODF for my project.
ecloud last edited by
hisoft and durgeshK: did you ever write a bug about this? I tried your code on OS X. The resulting doc is as you say if I open with LibreOffice: the author and date are missing. But if I open it with TextEdit, that text is there, but the image is missing.
Meanwhile someone wrote another bug about ODF support: https://bugreports.qt-project.org/browse/QTBUG-30924
Serenity last edited by
The bad odf support is already reported: https://bugreports.qt-project.org/browse/QTBUG-29555
It looks like, that the ODF Support doesn't work really well. There are a lot of problems, but it got a low prio.
I tried it really out, try to make simple example, and there are a lot of problems with this function. It really looks like, that nobody cares about that so much.