Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-27683

ODT file produced by QTextDocumentWriter/with QTextEdit produces invalid output with Unicode Text, doesn't preserve formatting information, cannot be opened with most word processors

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Out of scope
    • Affects Version/s: 4.8.3
    • Fix Version/s: None
    • Component/s: GUI: Text handling
    • Labels:
      None
    • Environment:
      QT 4.8.3, Open source (windows x86) version with MingGW GCC 4.4.0, Windows 7 OS (64 bit), QT creator 2.5.2

      Description

      When QTextDocumentWriter is used to write a ODT file, with the content taken from a QTextEdit, and the text contains Unicode Indic characters, with font information like font name, size, weight, style etc, the resulting ODT file is corrupt.

      All word processors fail to open the resulting odt file properly

      I tried with following Word Processors

      MS word 2010 - Fails to open the file itself, and terms it as corrupt
      AbiWord 2.8.6 - Opens but content is invalid/not readable
      Calligra 2.5 beta - Opens, content has no formatting information
      libreoffice 3.6.2.2 - Opens, content has no formatting information
      OpenOffice.org 3.4.1 - Opens, content has no formatting information

      Also attaching various error screenshots, the invalid odf file and the program used to generate the file.

      Following code was used to generate the file.

      #include <QApplication>
      #include <QtGui>
      
      #include "mainwindow.h"
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          QTextEdit edit;
      
          QString content;
      
          for (int i = 0; i < 100; i++)
              content += QChar(0x905);
      
          edit.setHtml(content);
      
          QTextCursor tc = edit.textCursor();
          tc.document()->setDefaultFont(QFont("Arial", 14));
      
      
      
          QTextCharFormat tcf = tc.charFormat();
          tc.select(QTextCursor::Document);
      
          tcf.setFontItalic(true);
          tcf.setFontWeight(QFont::Bold);
      
          tc.mergeCharFormat(tcf);
      
          edit.show();
      
      
          QTextDocumentWriter tdw;
          tdw.setFormat("odf");
          tdw.setFileName("c:/invalid_file.odt");
          bool saved = tdw.write(edit.document());
      
          
          return a.exec();
      }
      

      Also note, in the application, the text was set to bold and that also is not visible, as can be seen from the various screenshots provided here.

        Attachments

        1. abiword_2.8.6_odt_error.png
          abiword_2.8.6_odt_error.png
          47 kB
        2. calligra_2.5_beta_odf_error.png
          calligra_2.5_beta_odf_error.png
          99 kB
        3. invalid_file.odt
          0.9 kB
        4. libreoffice_3.6.2.2_odf_error.png
          libreoffice_3.6.2.2_odf_error.png
          78 kB
        5. ms_word2010_invalid_odt.png
          ms_word2010_invalid_odt.png
          88 kB
        6. ms_word2010_odt_error.png
          ms_word2010_odt_error.png
          84 kB
        7. OdfBug.zip
          518 kB
        8. open_office.org_3.4.1_odt_error.png
          open_office.org_3.4.1_odt_error.png
          73 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            esabraha Eskil Abrahamsen Blomfeldt
            Reporter:
            tarkshya Ram
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes