PDA

View Full Version : QGraphicsView and QGraphicsScene signals and slots



bruceariggs
18th November 2011, 15:16
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:



Object::connect: No such signal QGraphicsScene::focusPointChanged( int, int )
Object::connect: No such slot QGraphicsView::enableMouseTracking( bool )
Object::connect: No such slot QGraphicsView::acknowledgePressed()
Object::connect: No such slot QGraphicsView::panLeft()
Object::connect: No such slot QGraphicsView::panRight()
Object::connect: No such slot QGraphicsView::panUp()
Object::connect: No such slot QGraphicsView::panDown()
Object::connect: No such slot QGraphicsView::setFollowOwnship( bool )
Object::connect: No such slot QGraphicsView::resetView()
Object::connect: No such slot QGraphicsView::toggleFreeze()
Object::connect: No such slot QGraphicsView::increaseScale()
Object::connect: No such slot QGraphicsView::decreaseScale()
Object::connect: No such slot QGraphicsView::setNorthUp( bool )
Object::connect: No such slot QGraphicsView::addWaypoint()
Object::connect: No such slot QGraphicsView::addMarkpointAtOwnship()
Object::connect: No such slot QGraphicsView::setMarkpointCursor()
Object::connect: No such slot QGraphicsScene::toggleRing( int )
Object::connect: No such slot QGraphicsScene::clearTargets()
Object::connect: No such slot QGraphicsScene::updateWaypoints()
Object::connect: No such slot QGraphicsScene::clearRoute()
Object::connect: No such signal QGraphicsView::launchRouteDialog()
Object::connect: (receiver name: 'ChartPage')
Object::connect: No such signal QGraphicsView::launchTargetDialog()
Object::connect: (receiver name: 'ChartPage')
Object::connect: No such slot QGraphicsScene::updateTargetRouteIndex( short )
Object::connect: (sender name: 'ChartPage')


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

stampede
21st November 2011, 08:36
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 ?

Oleg
21st November 2011, 12:51
AFAIR, you should connect to QGraphicsView::viewport() signals.

bruceariggs
21st November 2011, 15:28
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!