Results 1 to 3 of 3

Thread: Error: passing 'const QString' as 'this' argument of 'QString& QString::operator=

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    254
    Thanks
    23
    Thanked 16 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Error: passing 'const QString' as 'this' argument of 'QString& QString::operator=

    Hi,

    I am getting this error:

    Qt Code:
    1. error: passing 'const QString' as 'this' argument of 'QString& QString::operator=(const QString&)' discards qualifiers
    To copy to clipboard, switch view to plain text mode 

    In this code
    Qt Code:
    1. void fixComboDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
    2. const QModelIndex &index) const
    3. {
    4. QString description;
    5. description = "Something";
    6. temp = description;
    7. }
    To copy to clipboard, switch view to plain text mode 

    temp is declared in the h as a private member
    Qt Code:
    1. private:
    2. QString temp;
    To copy to clipboard, switch view to plain text mode 

    why? And how can I do temp = description;!!!

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error: passing 'const QString' as 'this' argument of 'QString& QString::operator

    You can't because the method is const -- it can't change any of the object fields. Such assignment in the delegate's paint routine wouldn't make any sense anyway. The delegate will be called in some time for some totally different item and what would such "temp" variable be helpful with?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    qlands (11th August 2011)

  4. #3
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    254
    Thanks
    23
    Thanked 16 Times in 13 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Error: passing 'const QString' as 'this' argument of 'QString& QString::operator

    yep! I was doing something stupid!

    Thanks

Similar Threads

  1. Replies: 4
    Last Post: 20th August 2010, 13:54
  2. Replies: 4
    Last Post: 1st February 2010, 14:21
  3. error passing QString ?
    By vieraci in forum Qt Programming
    Replies: 2
    Last Post: 31st May 2009, 12:10
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. Replies: 2
    Last Post: 20th May 2006, 12:45

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.