下面的代码片段导致我的编译产生“错误:传递'const QRect‘作为'void QRect::setHeight(int)’的'this‘参数丢弃限定符-fpermissive”。
我如何解决这个问题?我还注意到,如果我将h -= 80;替换为h--;,编译器不会报错。
int h = this->geometry().height();
h -= 80;
ui->datumTable->geometry().setHeight(h);发布于 2013-05-20 22:04:54
geometry() returns a const reference to a QRect object inside QTableWidget.
它应该是一个只读的getter。你应该复制一份,修改它,然后用setGeometry设置函数重新设置它:
QRect rect = this->geometry();
int h = rect.height();
rect.setHeight(h - 80);
ui->datumTable->setGeometry(rect);发布于 2013-05-20 22:05:14
QRect g = this->geometry().height();
g.setHeight(g.height()-80);
ui->datumTable->setGeometry(g);发布于 2013-05-20 22:01:20
看起来datumTable中的geometry()返回了一个const QRect。除非也有非常量版本,否则不是一个简单的修复。
https://stackoverflow.com/questions/16651186
复制相似问题