Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.2.1
-
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.