PDA

View Full Version : Cannot use QRect::setWidth



WilliamSpiderWeb
3rd March 2011, 22:02
When I try to set the width of a modified QDockWidget



int iWidth = 500;
this->geometry().setWidth(iWidth);


I get the following error.



passing 'cost QRect' as 'this' argument of 'void QRect::setWidth(int)' discards qualifier


I have no idea what that error means and why I can't use such a simple function.

wysota
3rd March 2011, 22:40
It means you are trying to modify an object that is const.

ChrisW67
3rd March 2011, 22:43
passing 'const QRect' as 'this' argument of 'void QRect::setWidth(int)' discards qualifier

Contains two clues. You have a constant object that you are trying to use a non-const method on. The "discards qualifier" refers to attempting to discard the "const". This is an error and basic C++.

QWidget::geometry() (http://doc.trolltech.com/latest/qwidget.html#geometry-prop) is defined:


const QRect & geometry () const

You cannot modify a const QRect.

You can modify the geometry through the QWidget::setGeometry() method.

WilliamSpiderWeb
4th March 2011, 15:45
Thank you,
that was really stupid...

When I read your post I remembered that I used setGeometry() before.