Results 1 to 4 of 4

Thread: QGraphicsView and QGraphicsScene signals and slots

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12

    Default QGraphicsView and QGraphicsScene signals and slots

    Okay,

    I am trying to get a class that inherits from QGraphicsView (ChartViewer) and a class that inherits from QGraphicsScene (ChartScene) to use signals and slots to work with another class that inherits from QWidget (ChartPage).

    ChartPage works fine with signals and slots to other objects.

    ChartViewer and ChartScene however, cannot seem to use signals and slots. When I put the Q_OBJECT part at the beginning of the class, the code doesn't even seem to run. When I remove the Q_OBJECT part but leave my signals and slots in, the code builds, but all of my connect functions return a "No such signal: SIGNAL_NAME in QGraphicsView" for any signal or slot for either the view or the scene.

    Here's a sample of the output I get:

    Qt Code:
    1. Object::connect: No such signal QGraphicsScene::focusPointChanged( int, int )
    2. Object::connect: No such slot QGraphicsView::enableMouseTracking( bool )
    3. Object::connect: No such slot QGraphicsView::acknowledgePressed()
    4. Object::connect: No such slot QGraphicsView::panLeft()
    5. Object::connect: No such slot QGraphicsView::panRight()
    6. Object::connect: No such slot QGraphicsView::panUp()
    7. Object::connect: No such slot QGraphicsView::panDown()
    8. Object::connect: No such slot QGraphicsView::setFollowOwnship( bool )
    9. Object::connect: No such slot QGraphicsView::resetView()
    10. Object::connect: No such slot QGraphicsView::toggleFreeze()
    11. Object::connect: No such slot QGraphicsView::increaseScale()
    12. Object::connect: No such slot QGraphicsView::decreaseScale()
    13. Object::connect: No such slot QGraphicsView::setNorthUp( bool )
    14. Object::connect: No such slot QGraphicsView::addWaypoint()
    15. Object::connect: No such slot QGraphicsView::addMarkpointAtOwnship()
    16. Object::connect: No such slot QGraphicsView::setMarkpointCursor()
    17. Object::connect: No such slot QGraphicsScene::toggleRing( int )
    18. Object::connect: No such slot QGraphicsScene::clearTargets()
    19. Object::connect: No such slot QGraphicsScene::updateWaypoints()
    20. Object::connect: No such slot QGraphicsScene::clearRoute()
    21. Object::connect: No such signal QGraphicsView::launchRouteDialog()
    22. Object::connect: (receiver name: 'ChartPage')
    23. Object::connect: No such signal QGraphicsView::launchTargetDialog()
    24. Object::connect: (receiver name: 'ChartPage')
    25. Object::connect: No such slot QGraphicsScene::updateTargetRouteIndex( short )
    26. Object::connect: (sender name: 'ChartPage')
    To copy to clipboard, switch view to plain text mode 

    So... can QGraphicsView and QGraphicsScene use signals and slots? If so... what's the trick to getting that to happen?

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanked 342 Times in 324 Posts

    Default Re: QGraphicsView and QGraphicsScene signals and slots

    When I remove the Q_OBJECT part but leave my signals and slots in, the code builds, but all of my connect functions return a "No such signal: SIGNAL_NAME in QGraphicsView" for any signal or slot for either the view or the scene.
    You cannot expect it to work without the Q_OBJECT macro:
    The Q_OBJECT macro must appear in the private section of a class definition that declares its own signals and slots or that uses other services provided by Qt's meta-object system.
    When I put the Q_OBJECT part at the beginning of the class, the code doesn't even seem to run
    What do you mean by "code doesn't even seem to run" ? Can you post it ?

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

    bruceariggs (21st November 2011)

  4. #3
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android
    Thanks
    10
    Thanked 27 Times in 22 Posts

    Default Re: QGraphicsView and QGraphicsScene signals and slots

    AFAIR, you should connect to QGraphicsView::viewport() signals.
    Oleg Shparber

  5. The following user says thank you to Oleg for this useful post:

    bruceariggs (21st November 2011)

  6. #4
    Join Date
    Aug 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    12

    Cool Re: QGraphicsView and QGraphicsScene signals and slots

    Finally!

    I couldn't post the code, so I started writing a little sample app, and much to my surprise, the sample app. was working!

    So I took a look back at my original code, and it had the same stuff in it! I was very confused.

    SOLUTION: The clean function wasn't cleaning my build folder. I had to go and manually clean it. And by clean I mean DELETE EVERYTHING THAT EVER EXISTED THAT EVEN REMOTELY MESSED WITH ME OR MY BEAUTIFUL CODE. Now it builds. Without issues. Thanks for your help everyone. Sorry I'm such a tard!

Similar Threads

  1. QT SIGNALS and SLOTS
    By beginQT in forum Newbie
    Replies: 7
    Last Post: 23rd September 2011, 14:40
  2. about signals and slots
    By Sandip in forum Qt Programming
    Replies: 9
    Last Post: 15th July 2008, 16:02
  3. Signals and slots
    By sylvarant in forum Newbie
    Replies: 4
    Last Post: 11th September 2007, 15:48
  4. Signals and Slots
    By merry in forum Qt Programming
    Replies: 4
    Last Post: 22nd February 2007, 08:11
  5. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 08:12

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
  •  
Qt is a trademark of The Qt Company.