Results 1 to 3 of 3

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

  1. #1
    Join Date
    Nov 2011
    Location
    Brazil
    Posts
    10
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Error "request for member which is of non-class type" using QList pointers

    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:
    Qt Code:
    1. ...
    2. private:
    3. QList<QGraphicsEllipseItem*> point;
    4. QList<QGraphicsTextItem*> pointLabel;
    5. ...
    To copy to clipboard, switch view to plain text mode 

    source (working part - notice I'm successfully using the list entries as pointers):
    Qt Code:
    1. void WhiteSpaceView::insertPoint(...)
    2. {
    3. point.append(new QGraphicsEllipseItem(...));
    4. point.last()->setFlags(...);
    5. pointLabel.append(...);
    6. pointLabel.last()->moveBy(...);
    7. insideScene->addItem(point.last());
    8. insideScene->addItem(pointLabel.last());
    9. }
    To copy to clipboard, switch view to plain text mode 

    source (not working part)
    Qt Code:
    1. void WhiteSpaceView::setShowLabels()
    2. {
    3. QList<QGraphicsTextItem*>::Iterator i;
    4. for(i=pointLabel.begin();i!=pointLabel.end();++i)
    5. { i->setVisible(isShowLabels); }
    6. }
    To copy to clipboard, switch view to plain text mode 

    error: request for member ‘setVisible’ in ‘* i.QList<T>::iterator:perator-> [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!

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Error "request for member which is of non-class type" using QList pointers

    i is an iterator. The thing it "points" to, i.e. *i, is a pointer to QGraphicsTextItem. You want this:
    Qt Code:
    1. (*i)->setVisible(isShowLabels);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    mwgobetti (22nd November 2011)

  4. #3
    Join Date
    Nov 2011
    Location
    Brazil
    Posts
    10
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Error "request for member which is of non-class type" using QList pointers

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

Similar Threads

  1. Replies: 4
    Last Post: 25th February 2011, 09:01
  2. "Treat wchar_t as Built-in Type" to "yes" link error
    By sungaoyong in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2008, 11:45
  3. Replies: 4
    Last Post: 19th March 2008, 17:47
  4. Compilation error: "field 'xxx' has incomplete type"
    By fedcer in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2007, 15:01
  5. QList with "local type"
    By drhex in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2007, 05:07

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.