1

The follow snippet results in my compilation yielding "error: passing 'const QRect' as 'this' argument of 'void QRect::setHeight(int)' discards qualifiers [-fpermissive]".

How can I fix this and also I've noticed that if I were to replace h -= 80; with h--;, the compiler does not complain.

int h = this->geometry().height();
h -= 80;
ui->datumTable->geometry().setHeight(h);
johnsonwi
  • 159
  • 3
  • 15

3 Answers3

2

geometry() returns a const reference to a QRect object inside QTableWidget.

It's meant to be a read-only getter. You should take a copy, modify it and set it back with setGeometry setter function:

QRect rect = this->geometry();
int h = rect.height();
rect.setHeight(h - 80);
ui->datumTable->setGeometry(rect);
Alex B
  • 82,554
  • 44
  • 203
  • 280
1
QRect g = this->geometry().height();
g.setHeight(g.height()-80);
ui->datumTable->setGeometry(g);
Dan Milburn
  • 5,600
  • 1
  • 25
  • 18
0

It would seem that geometry() in datumTable returns a const QRect. Not an easy fix unless there is a non-const version as well.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • pretty sure the same code has worked in qt on windows, could this be a linux variant problem/bug ? This needn't be a difficult problem – johnsonwi May 20 '13 at 14:03
  • @johnsonwi Because the returned value is a const reference, so the compiler won't let you modify it. – Alex B May 20 '13 at 14:12