Option 1:
Simplify the white space, then remove it
Per the docs
[QString::simplified] Returns a string that has whitespace removed from the start and the end, and that has each sequence of internal whitespace replaced with a single space.
Once the string is simplified, the white spaces can easily be removed.
str.simplified().remove(' ')
Option 2:
Use a QRegExp to capture all types of white space in remove.
QRegExp space("\\s");
str.remove(space);
Notes
- The OPs string has white space of different types (tab, carriage return, new line), all of which need to be removed. This is the tricky part. 
- QString::removewas introduced in Qt 5.6; prior to 5.6 removal can be achieved using- QString::replaceand replacing the white space with an empty string- "".