Stack overflow when using MouseMoveEvent
-
Hi,
So i tried to implement a scene with a moving view with the view moving when the mouse is near one of the borders of the screen (like in most RTS games). However i get a stack overflow when i do that.
My function looks like thisvoid Camera::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
{
//view coordinates
int local_x = view->mapFromScene(e->pos()).x();
int local_y = view->mapFromScene(e->pos()).y();int horizontalSliderPos = view->horizontalScrollBar()->sliderPosition(); int verticalSliderPos = view->verticalScrollBar()->sliderPosition(); if (local_x < 100) { view->horizontalScrollBar()->setSliderPosition(horizontalSliderPos -5); }
This code is only for the one direction to make it easier. Could someone please enlighten me where or how an overflow is occuring here?
-
Hi,
Aren't you triggering an infinite recursion ?
-
I mean probably. Thats where the stack overflow should come from i guess. But my question was where this occurs oe rather how can i fix that?
Edit: From my (limited) understanding it should come from the fact that i trigger this event infinite times once the mouse is in the stated area. A fix for this would be to stop the event from happening once the slider is at its max/min position, but i have no idea how i would do that.
-
Rather than relying on the slider position, shouldn't you rather define zones in which if the cursor can be found, the scrollbars are updated ?
-
Something is not clear from your code, what class is Camera ?
-
I mean probably. Thats where the stack overflow should come from i guess. But my question was where this occurs oe rather how can i fix that?
Edit: From my (limited) understanding it should come from the fact that i trigger this event infinite times once the mouse is in the stated area. A fix for this would be to stop the event from happening once the slider is at its max/min position, but i have no idea how i would do that.
@infestor said in Stack overflow when using MouseMoveEvent:
Thats where the stack overflow should come from i guess
Simply looking at the backtrace will show it, it will also show you why it's a recursion.