Results 1 to 4 of 4

Thread: invalid use of member (did you forget the '&')

  1. #1
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Smile invalid use of member (did you forget the '&')

    Hello all and thank you for viewing my question:

    I have a button (pushButton) in my form MainWindow which I have set up to execute a method by using Go to Slot... in qt designer:

    This is the method's body:

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QColor black ("black");
    4. QPen pen (black);
    5. scene->addLine(0,0,250,250,pen);
    6.  
    7. this->ui->graphicsView->scene=scene;
    8.  
    9. }
    To copy to clipboard, switch view to plain text mode 
    I get a compile time error message in the line, this->ui->graphicsView->scene=scene:
    error: invalid use of member (did you forget the '&' ?).

    The problem is I am a complete beginner to unmanaged software development so this might a beginners problem with pointers but I tried to search Google and C++ tutorials and other Qt forums but alas no luck.

    Please post beginners tips about pointer related conventions you use to prevent pointer problems anyway because I was pulling my hair with pointer problems .
    Thank you for helping!!!!!!!!!!!!!!!!!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: invalid use of member (did you forget the '&')

    You need to use the setScene() function.

    scene might be an internal variable for the QGraphicsView class, not meant to be used by anyone.
    Edit: as seen it the QGraphicsView private header:
    Qt Code:
    1. QPointer<QGraphicsScene> scene;
    To copy to clipboard, switch view to plain text mode 

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

    KBMoiloa (21st May 2011)

  4. #3
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: invalid use of member (did you forget the '&')

    I suspect that the object graphicsView (and not its pointer) is a member of ui, so you should use ui.graphicsView. But it's hard to say without seeing the rest of the code.

    Note that there are several versions of the UI Designer, and they differ in terms of what elements are "inlined" vs pointed to. So you can't always blindly copy examples.

  5. #4
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: invalid use of member (did you forget the '&')

    SOLVED, yes scene is actually not meant to be used by anyone. Thanks tbscope !!!!!!!!!!!!!!!!

Similar Threads

  1. invalid use of this in non member function
    By dineshkumar in forum Qt Programming
    Replies: 7
    Last Post: 13th December 2015, 19:37
  2. fire and forget way for QProcess
    By qt_gotcha in forum Newbie
    Replies: 2
    Last Post: 17th August 2010, 19:42
  3. Replies: 22
    Last Post: 8th October 2008, 13:54
  4. intersectingStaticSet: row 'x' was invalid
    By Kumosan in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2007, 15:41
  5. error:invalid use of member
    By quickNitin in forum General Programming
    Replies: 4
    Last Post: 19th June 2006, 15:21

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.