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

Qt Code:
  1. QTextCursor lOrgPosition = aEditor->textCursor();
  2. //QRegExp lRe(QString("(?: |\\t)+") + QChar(0x2029));
  3. QRegExp lRe("(?: |\\t)+\\n");
  4. lRe.setMinimal(true);
  5.  
  6. QTextDocument* lDoc = aEditor->textCursor().document();
  7. QTextCursor lCursor = lDoc->find(lRe, 0);
  8. while(!lCursor.isNull())
  9. {
  10. lCursor.removeSelectedText();
  11. lCursor = lDoc->find(lRe, lCursor.position());
  12. }
  13. aEditor->setTextCursor(lOrgPosition);
To copy to clipboard, switch view to plain text mode