Please helpQString remove function to remove const string
I want to remove blank space from a const string, but when i used remove function its showing error that const string cant modify.
const QString abc = "hello world";
QString def = " ";
QString mk = abc .remove(def); // Here error 开发者_开发问答saying const cant change
Please Help
You can't modify a const String. QString::remove returns a reference to abc, so remove works on abc, mk is not a copy but abc again!! Look for functions which are const functions if you want to operate on a const object.
EDIT:
const QString abc = "hello world";
QString ijk = abc;
QString def = " ";
QString mk = ijk .remove(def); // Here error saying const cant change
The same operation without additional variable:
const QString abc = "hello world";
QString def = " ";
QString mk = abc;
mk.remove(def);
精彩评论