I am going crazy with this problem.
I have this self-defined struct
struct oneRectangle
{
QString partName;
QGraphicsRectItem * rectangle;
};
And I have a List use this struct as a template:
QList<oneRectangle> partList;
After I append an entity of struct(without init the pointer), I need to do something like this:
partList.at(index).rectangle = some pointer points to a QGraphicsRectItem
But, I got an error saying the struct is a read-only struct. I tried to malloc the pointer first, then append it to the list, But when I assign address to the pointer, I still get the error.
What’s the problem here?
Change
into
as
QList::operator[](int)returns a modifiable reference, whereQList::at(int)returns a const reference (and is thus not modifiable).