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

QTextCharFormat fontFamily asserts

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.2.1
    • GUI: Text handling
    • None

    Description

      This code works in Qt 5 and asserts in Qt 6:

      
      #include <QDebug>
      #include <QTextDocument>
      #include <QTextFrame>
      
      int main(int argc, char** argv)
      {
      
          QTextDocument doc;
      
          doc.setHtml("Some <b>formatted</b> text.");
      
          auto frame = doc.rootFrame();
      
          auto fit = frame->begin();
          auto fend = frame->end();
      
          while (!fit.atEnd() && fit != fend) {
              auto frame = fit.currentFrame();
              auto block = fit.currentBlock();
              auto bit = block.begin();
              auto bend = block.end();
              while(!bit.atEnd())
              {
                  auto f = bit.fragment();
                  auto ff = f.charFormat().fontFamily();
                  qDebug() << "FRAG" << f.text() << ff;
                  ++bit;
              }
              ++fit;
          }
          return 0;
      }
      
      

      The `fontFamily` call in

                  auto ff = f.charFormat().fontFamily();
      

      is deprecated, but usually "deprecated" means "still works, but port away from it". In this case, it is broken.

      Additionally, the documentation recommends the use of `fontFamilies` instead. That API returns a QVariant, but the docs do not offer any assistance regarding what the QVariant might contain. The fontFamilies API should probably be deprecated in favor of a method which returns a different type than QVariant.

      Attachments

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

        Activity

          People

            andysh Andy Shaw
            steveire Stephen Kelly (Personal)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes