PDA

View Full Version : Error: passing 'const QString' as 'this' argument of 'QString& QString::operator=



qlands
11th August 2011, 15:19
Hi,

I am getting this error:



error: passing 'const QString' as 'this' argument of 'QString& QString::operator=(const QString&)' discards qualifiers


In this code


void fixComboDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QString description;
description = "Something";
temp = description;
}


temp is declared in the h as a private member


private:
QString temp;


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

Thanks!

wysota
11th August 2011, 15:26
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?

qlands
11th August 2011, 15:42
yep! I was doing something stupid!

Thanks