PDA

View Full Version : Error "request for member which is of non-class type" using QList pointers



mwgobetti
22nd November 2011, 04:02
Hi all! I'm still surprised by the amount of wise and generous people in these forums :)

I've got another problem which I could not figure out by myself. I'm using QList as an array of pointers, because I need it to be expansible and contractible and found it was the best way to do it. For what I wanted firstly, it's working just as it should. Got some problems now, though. Showing some code:

header:

...
private:
QList<QGraphicsEllipseItem*> point;
QList<QGraphicsTextItem*> pointLabel;
...

source (working part - notice I'm successfully using the list entries as pointers):

void WhiteSpaceView::insertPoint(...)
{
point.append(new QGraphicsEllipseItem(...));
point.last()->setFlags(...);
pointLabel.append(...);
pointLabel.last()->moveBy(...);
insideScene->addItem(point.last());
insideScene->addItem(pointLabel.last());
}

source (not working part)

void WhiteSpaceView::setShowLabels()
{
QList<QGraphicsTextItem*>::Iterator i;
for(i=pointLabel.begin();i!=pointLabel.end();++i)
{ i->setVisible(isShowLabels); }
}


error: request for member ‘setVisible’ in ‘* i.QList<T>::iterator::operator-> [with T = QGraphicsTextItem*]()’, which is of non-class type ‘QGraphicsTextItem*’

I didn't understand this error since I successfully used the entries as pointers in the other part of the code.
Any guesses?

Thank you all in advance!

ChrisW67
22nd November 2011, 04:06
i is an iterator. The thing it "points" to, i.e. *i, is a pointer to QGraphicsTextItem. You want this:


(*i)->setVisible(isShowLabels);

mwgobetti
22nd November 2011, 05:19
Great! I tried *i->setVisible(isShowLabels);
with what you said in mind, but I didn't know about the parentheses thing.
Thanks a lot! :)