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.