Hello
I write text editor and I want to remove trailing spaces from document before save. I think the right way is to use
QTextCursor QTextDocument::find(const QRegExp & expr, int position = 0, FindFlags options = 0) const
for that. So I write regular expression and I tested it in separated program (based on regexp example from qt framework). But sadly it not works and I don't known why. It seems that problem lies in \n character. My code is below (both regexps don't work). Please tell me what I am doing wrong.
best regards
Szyk Cech
//QRegExp lRe(QString("(?: |\\t)+") + QChar(0x2029));
lRe.setMinimal(true);
while(!lCursor.isNull())
{
lCursor.removeSelectedText();
lCursor = lDoc->find(lRe, lCursor.position());
}
aEditor->setTextCursor(lOrgPosition);
QTextCursor lOrgPosition = aEditor->textCursor();
//QRegExp lRe(QString("(?: |\\t)+") + QChar(0x2029));
QRegExp lRe("(?: |\\t)+\\n");
lRe.setMinimal(true);
QTextDocument* lDoc = aEditor->textCursor().document();
QTextCursor lCursor = lDoc->find(lRe, 0);
while(!lCursor.isNull())
{
lCursor.removeSelectedText();
lCursor = lDoc->find(lRe, lCursor.position());
}
aEditor->setTextCursor(lOrgPosition);
To copy to clipboard, switch view to plain text mode
Bookmarks