3

我有一个圆形对象,它包含绘制它的属性,如宽度、坐标 xy、颜色。我有一个这个圆圈(对象)的 qlist,但是当我尝试更改颜色时出现错误。

class Circle {
 int x;
 int y;
 int width;
 QColor color
}

QList <Circle> circles;

我在列表中添加了一些圈子,这是问题所在

circles.at(3).color = Qt::yellow;

将 'const QColor' 作为 'QColor& QColor::operator=(Qt::GlobalColor)' 的 'this' 参数传递会丢弃限定符 [-fpermissive]

4

1 回答 1

14

The at() function of a QList returns a const reference: const T & QList::at(int i) const, so you can not modify it. Use operator[] instead: circles[3].color = Qt::yellow

Also note that right now all members of your class are private (by default), so you will not be able to set color anyway.

于 2013-10-10T05:40:55.550 回答