Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why my ODF (.odt) file is not generated correctly with QTextDocumentWriter ?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
10 Posts 5 Posters 7.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hisoft
    wrote on last edited by
    #1

    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;
    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&#40;&#41;;
    

    }
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

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

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hisoft
        wrote on last edited by
        #3

        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.
        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          Can you create a complete test case, the snippet does not compile (the cursor variable is undefined).

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hisoft
            wrote on last edited by
            #5

            Complete test created (old posted code is edited) !

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hisoft
              wrote on last edited by
              #6

              Nobody has an idea ?

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                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.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  durgeshK
                  wrote on last edited by
                  #8

                  Hello people,

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

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    ecloud
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Serenity
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved