Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Stack overflow when using MouseMoveEvent
Forum Updated to NodeBB v4.3 + New Features

Stack overflow when using MouseMoveEvent

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 772 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Infestor
    wrote on last edited by
    #1

    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 this

    void 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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Aren't you triggering an infinite recursion ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Infestor
        wrote on last edited by Infestor
        #3

        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.

        Christian EhrlicherC 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Infestor
            wrote on last edited by
            #5

            Isnt that what im doing? I only update the slider position if the cursor (local_x/y) is at a specific location (< 100 in this case for x).

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Something is not clear from your code, what class is Camera ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • I Offline
                I Offline
                Infestor
                wrote on last edited by
                #7

                It inherits from QGraphicsRectItem and does not much else right now. It is added to the scene in the main class and then it grabs the mouse as otherwise the mouseMoveevent does not work.

                1 Reply Last reply
                0
                • I Infestor

                  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.

                  Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved