Results 1 to 3 of 3

Thread: error passing QString ?

  1. #1
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question error passing QString ?

    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:

    Qt Code:
    1. QString getPhoneMask(const QString &text)
    2. {
    3. QString tmp = text.remove(QRegExp("[()-]"));
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Dec 2008
    Location
    TaganrogNativelandChehov,Russia
    Posts
    64
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error passing QString ?

    I think that you cannot change const object
    Qt Code:
    1. QString getPhoneMask(const QString &text)
    2. text.remove(QRegExp("[()-]"));
    To copy to clipboard, switch view to plain text mode 
    you can write
    Qt Code:
    1. QString getPhoneMask(const QString &text)
    2. {
    3. QString tmp = text;
    4. tmp = tmp.remove(QRegExp("[()-]"));
    5. //
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to kwisp for this useful post:

    vieraci (31st May 2009)

  4. #3
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error passing QString ?

    Wow OK, I didn't think remove() changed the original string.
    Thanks for pointing this out.

Similar Threads

  1. Qy 4.4.3 MySQL driver failed
    By pamalite in forum Installation and Deployment
    Replies: 2
    Last Post: 23rd January 2010, 01:09
  2. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  3. easiest Way QString can do
    By baray98 in forum Qt Programming
    Replies: 12
    Last Post: 15th April 2008, 20:49
  4. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  5. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.