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

QTextCursor::insertHtml() may break formatting

    XMLWordPrintable

Details

    Description

      Consider the following example:

      #include <QtGui>

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

      QTextEdit edit1;
      QTextEdit edit2;

      QStringList items;

      items << "<font color=\"blue\"><pre>---- 13:24:58.118 ------------------\n"
      "MESSAGE_ONE\n"
      "(1) Trailing newlines before a closing PRE get stripped\n"
      "------------------------------------\n"
      "</pre></font>\n";

      items << "<font color=\"green\"><pre>---- 13:24:58.118 ------------------\n"
      "MESSAGE_TWO\n"
      "The first line of this has run up against the last line of MESSAGE_ONE\n"
      "------------------------------------\n"
      "</pre></font>\n";

      items << "<p> </p><p> </p><p> </p>";

      items << "<font color=\"blue\"><pre>---- 13:24:58.118 ------------------\n"
      "MESSAGE_ONE\n"
      "(3) Additionally, the HR below this message \n"
      "seems to be appearing in the wrong place\n"
      "------------------------------------\n"
      "</pre></font>\n";

      items << "<p><hr/></p>";

      items << "<font color=\"green\"><pre>---- 13:24:58.118 ------------------\n"
      "MESSAGE_TWO\n"
      "details\n"
      "------------------------------------\n"
      "</pre></font>\n";

      QString html;
      QTextCursor cursor = edit1.textCursor();

      foreach(QString item, items)

      { cursor.insertHtml(item); html.append(item); }

      cursor = edit2.textCursor();
      cursor.insertHtml(html);

      edit1.show();
      edit2.show();

      return app.exec();
      }

      The expected result is that both QTextEdits display the content in the same way. However, edit1 which uses QTextCursor::insertHtml() for each item in the string list, does not display the HTML correctly. The formatting is broken: The end of the first <pre> block and the the beginning of the second <pre> block appear on the same line, and the <hr> tag which should be rendered between the two <pre> blocks in a separate paragraph, is rendered between the two first lines of the last <pre> tag instead.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            shausman Simon Hausmann
            sthomass Stian Sandvik Thomassen (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes