Search code examples
c++qt

Remove whitespace from QTextEdit


A simple one for some I you I hope but I can't find it in the documentation.

uiText << text->toPlainText();

This is how I get the text from a QTextEdit.

How do I remove any whitespace?

Thanks.


Solution

  • QString has two methods for removing whitespace from a string.

    uiText << text->toPlainText().trimmed();

    would remove any whitespace at the beginning and end of the string, while

    uiText << text->toPlainText().simplified();

    would remove any whitespace at the beginning and end of the string and also reduce each sequence of whitespace inside the string to one space per occurrence.

    The QString documentation has example of both.