View Single Post
Old 08-06-2017, 03:05 PM   #6
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,654
Karma: 5433388
Join Date: Nov 2009
Device: many
For the record ... the Qt "bug" is here: Qt/qtbase/src/gui/text/qtextdocument.cpp
whose toPlainText() routine (which is used by QPlainTextEdit and QTextEdit) does the following and thereby changes all nbsp to normal spaces.

Code:
QString QTextDocument::toPlainText() const
{
    Q_D(const QTextDocument);
    QString txt = d->plainText();

    QChar *uc = txt.data();
    QChar *e = uc + txt.size();

    for (; uc != e; ++uc) {
        switch (uc->unicode()) {
        case 0xfdd0: // QTextBeginningOfFrame
        case 0xfdd1: // QTextEndOfFrame
        case QChar::ParagraphSeparator:
        case QChar::LineSeparator:
            *uc = QLatin1Char('\n');
            break;
        case QChar::Nbsp:
            *uc = QLatin1Char(' ');
            break;
        default:
            ;
        }
    }
    return txt;
}
Kovid creates his own class that subclasses the problem Qt class and creates his own version of this toPlainText() in which he uses a text cursor to highlight the entire document and then copy it out so he does not have to use the normal toPlainText call.

This Qt bug has been reported numerous times but it has never been fixed as they don't consider this a bug. Strange that they only mess with nbsp as no other char is played with.

Last edited by KevinH; 08-06-2017 at 03:08 PM.
KevinH is offline   Reply With Quote