Problem writing to Open Document Text Format (ODT)



  • I am building an application that attaches notes to records of events stored in a database, so if you wish to record a note against an Event in the Database you can do so, but you can also export notes within the Note Editor, saving them as plaintext, HTML, ODT (Open Document Text Format - used by Libre Office), PDF and you can print them.

    All of the above work well with the same data, in all the formats other than ODT, which if I use that, it only includes the first line of the text from a QTextDocument/QTextedit.

    If I include the lines:
    One
    Two
    Three

    I only get "One".

    The same problem occurs with longer lines of text

    I can type these directly into the QTextedit box or load them from a file that has either been created else where (in Kate the KDE Text editor), or in the Text Editor I am creating within the program, saving them as a file and reloading them. If I do this and Print it, save it to PDF or using QTextDocumentWriter to write it to plaintext or HTML it works perfectly. If I use QTextDocumentWriter to save it in ODT format I only get the first line, the "One" in the file.

    To lay out the document I use an HTML table and put the date and the subject in the top two rows and the body of the note in the bottom row. It works well in HTML and plaintext, but in ODT I just get one row, the first, when there should be three. The rest of the Table/Document is as it should be.

    I am using Qt 5.3.1 (GCC 4.6.1 64 bit) on Linux Mint KDE with Qt Creator 3.1.2, so a fairly standard and completely up to date configuration.

    The problem occurs if I compile and run in debug and release mode.

    I use this code to build the QString that becomes the file content:

    @QString Single_Note_string()
    {
    QString DocumentContent;
    DocumentContent = "<table border="1" bordercolor="#000099" style="background-color:#FFFFFF" cellpadding="3" cellspacing="3">";
    DocumentContent += QString("<tr><td><b>Subject:</b> %1</td></tr>").arg(ui->lineEdit_Subject->text());
    DocumentContent += QString("<tr><td><b>Date:</b> %1</td></tr>").arg(ui->dateTimeEdit_Creation->dateTime().toString("ddd - dd MMMM yyyy - hh:mm"));
    DocumentContent += QString("<tr><td>%1</td></tr>").arg(m_Note->toHtml());
    DocumentContent += "</table>";
    return DocumentContent;
    }@

    This is the code that creates the document and the Writer.setFormat line is the only line that varies for html and plain text (which both work):

    @qDebug() << Single_Note_string();
    
    QTextDocument temp_print_doc;
    temp_print_doc.setHtml(Single_Note_string());
    // I've removed the code that puts a file name into fileName.
    
    QTextDocumentWriter Writer(fileName);
    Writer.setFormat("odt");
    Writer.write(&temp_print_doc);@
    

    The qDebug() line displays all the text I would expect to see in the file and all the HTML formatting code, so the QString that is fed to it is correct.

    I am currently trying to install the latest version on my Windows 7 64 bit machine to see if that has the same problem.

    Am I missing something or does this indicate a bug, any suggestions?

    I would like to try this in Windows 7 as I can dual boot on my laptop, but am still having great difficulty getting the Window 7 versions to download and install with out error.

    Thanks.



  • The above problem also occours with Windows 7, in the Mingw482 version. I had to download the non-online version to get it to work


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.