Search code examples
c++qtqstring

Modifying a QString that contains a "\"


I'm trying to modify a QString. The Qstring that I'm trying to modify is

"\002"

However when I try to modify it, the string either gets entirely deleted or shows no change.

I've tried

String.split("\"");
String.remove("\"");
String.remove(QChar('\'');

for some reason Qt requires that I add an extra " or ' in order to compile and not produce errors

What I currently have is this

string = pointer->data.info.get_type();

which according to the debugger returns "\002"

string = string.remove(QChar('\''));

the remove functionality does nothing afterwards.

I'm expecting to remove the \ from the string, but either it gets entirely deleted or nothing happens. What could be the problem and how do I modify the Qstring to just be the numerical values?


Solution

  • You're currently asking Qt to remove " from your string, not \. To remove \, you'll have to escape it, just like you escaped ", i.e. remove("\\").