PDA

View Full Version : error passing QString ?



vieraci
31st May 2009, 12:39
I have this compile error which has got me stumped.


error: passing ‘const QString’ as ‘this’ argument of ‘QString& QString::remove(const QRegExp&)’ discards qualifiers

the code in question is:


QString getPhoneMask(const QString &text)
{
QString tmp = text.remove(QRegExp("[()-]"));


I don't understand this...can anyone decipher the message ?

kwisp
31st May 2009, 12:57
I think that you cannot change const object

QString getPhoneMask(const QString &text)
text.remove(QRegExp("[()-]"));

you can write


QString getPhoneMask(const QString &text)
{
QString tmp = text;
tmp = tmp.remove(QRegExp("[()-]"));
//

vieraci
31st May 2009, 13:10
Wow OK, I didn't think remove() changed the original string. :o
Thanks for pointing this out.