Important: Please read the Qt Code of Conduct -

Why my ODF (.odt) file is not generated correctly with QTextDocumentWriter ?

  • Hi,

    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 :

    #include <QtGui/QApplication>
    #include "mainwindow.h"

    #include <QTextDocument>
    #include <QTextCursor>
    #include <QTextFrameFormat>
    #include <QTextTable>
    #include <QImage>
    #include <QPrinter>
    #include <QTextDocumentWriter>

    int main(int argc, char *argv[])
    QApplication a(argc, argv);

    QTextDocument * doc = new QTextDocument();
    QTextCursor cursor(doc);
    QTextFrameFormat 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");
    // Footer
    cursor = table->cellAt(2, 0).firstCursorPosition();
    QTextTable * table2 = cursor.insertTable(1, 2) ;
    // Author
    cursor = table2->cellAt(0, 0).firstCursorPosition();
    // Date
    cursor = table2->cellAt(0, 1).firstCursorPosition();
    QPrinter printer(QPrinter::HighResolution);
    QTextDocumentWriter writer("rapport.odt");
    return a.exec&#40;&#41;;


  • Can you explain "but it does not work properly" a bit more detailed? Is anything written at all? Is it data incomplete or corrupted?

  • Hi,

    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": Please report back the the bug ID here, so that others can follow and vote for it.

  • Hello people,

    Any update on this issue? I am in desperate need to generate ODF for my project.

  • 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:

  • The bad odf support is already reported:

    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.

Log in to reply