PDA

View Full Version : Error with setRect in QRect



guidupas
11th June 2014, 21:02
Hello all!

I have a QRect and when I try to setRect it return this error

/QT/Projetos/VisaoFinanceira/fluxocaixawidget.cpp:174: error: member function 'setRect' not viable: 'this' argument has type 'const QRect', but function is not marked const
fluxoRect.at(i).setRect(7,7,7,7);

Thanks.

Here is the code:


QList<QRect> fluxoRect;

fluxoRect.append(QRect(0,0,0,0));

fluxoRect.at(i).setRect(7,7,7,7);

ChrisW67
11th June 2014, 21:27
The at() function returns a constant reference to a QRect in the list. You cannot modify a constant QRect. Try using the list's operator[]() to get a non-const reference.

guidupas
11th June 2014, 21:41
Thanks for the reply

I have solved it.



fluxoRect.at(i).replace(QRect(7,7,7,7));

wysota
12th June 2014, 07:33
I don't think the code you posted is going to work... You probably meant:


fluxoRect.replace(i, QRect(7,7,7,7));

Alternatively you could have done:


fluxoRect[i] = QRect(7,7,7,7);

or

fluxoRect[i].setRect(QRect(7,7,7,7));

which use the non-const variant of [] operator.

guidupas
12th June 2014, 14:22
wysota, thank you for your reply



fluxoRect.replace(i, QRect(7,7,7,7));


worked fine.