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. setPos() in a QGraphicsItem, finished the programm.
QtWS25 Last Chance

setPos() in a QGraphicsItem, finished the programm.

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicsitemruntimeerrorsetpos
10 Posts 4 Posters 5.0k Views
  • 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.
  • M Offline
    M Offline
    Mehonidas
    wrote on last edited by Mehonidas
    #1

    Hi all,
    i have trouble with my code.

    I have a class it inherit from QGraphicsItem and it update the position.
    I call the function render() in a gameloop (ca. 30 times a second). If i do this
    i got the runtimeerror "The program has unexpectedly finished." If i set the Position in the constructor
    it works, but i need to update it frequently.

    void Particle::render()
    {
         setPos(position.getX(),position.getY());
    }
    

    How can i update the Position frequently.

    I hope the question is not too simple.
    THX for help!
    Greetings Meho

    raven-worxR A 2 Replies Last reply
    1
    • M Mehonidas

      Hi all,
      i have trouble with my code.

      I have a class it inherit from QGraphicsItem and it update the position.
      I call the function render() in a gameloop (ca. 30 times a second). If i do this
      i got the runtimeerror "The program has unexpectedly finished." If i set the Position in the constructor
      it works, but i need to update it frequently.

      void Particle::render()
      {
           setPos(position.getX(),position.getY());
      }
      

      How can i update the Position frequently.

      I hope the question is not too simple.
      THX for help!
      Greetings Meho

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Mehonidas
      please retry with a debugger attached and show the stackstrace.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mehonidas
        wrote on last edited by Mehonidas
        #3

        Hi raven,
        thank you for respond.

        in debuging mode the following error appear:
        "The inferior stopped because it received a signal from the Operating System.

        Signal name :
        SIGSEGV
        Signal meaning :
        Segmentation fault"

        And here is the stack trace:
        I hope this is what you want? If you need more just say it.

        0 QGraphicsItem::setPos(QPointF const&) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff79b9708
        1 QGraphicsItem::setPos qgraphicsitem.h 495 0x4095c3
        2 Particle::render particle.cpp 15 0x40b2dc
        3 BombFactory::render bombfactory.cpp 42 0x40b6aa
        4 Game::gameLoop game.cpp 111 0x407722
        5 Game::qt_static_metacall moc_game.cpp 71 0x40c3ee
        6 QMetaObject::activate(QObject*, int, int, void**) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b4d2a6
        7 QTimer::timerEvent(QTimerEvent*) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b59622
        8 QObject::event(QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b4e054
        9 QApplicationPrivate::notify_helper(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff76ebc8c
        10 QApplication::notify(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5 0x7ffff76f0e56
        11 QCoreApplication::notifyInternal(QObject*, QEvent*) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b25c2d
        12 QTimerInfoList::activateTimers() /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b721ad
        13 ?? /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b72661
        14 g_main_context_dispatch /lib/x86_64-linux-gnu/libglib-2.0.so.0 0x7ffff55aae04
        15 ?? /lib/x86_64-linux-gnu/libglib-2.0.so.0 0x7ffff55ab048
        16 g_main_context_iteration /lib/x86_64-linux-gnu/libglib-2.0.so.0 0x7ffff55ab0ec
        17 QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b7298c
        18 QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b2496b
        19 QCoreApplication::exec() /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 0x7ffff6b2b0e1
        20 main main.cpp 15 0x407048

        The program stop at this lines:

        inline void QGraphicsItem::setPos(qreal ax, qreal ay)
        { setPos(QPointF(ax, ay)); }
        

        Thx for help!
        Greetings Meho

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Just for test.
          If u set timer to 2 secs or slower, does it still crash?

          1 Reply Last reply
          1
          • M Offline
            M Offline
            Mehonidas
            wrote on last edited by
            #5

            I tried it with a fixed frame rate of 1 und 2 frames per second.
            I got the same error :-(

            I have a class "Player", it inherits from QObject and QGraphicsPixmapItem.
            In this class it works fine.
            I tried to adapted as much as possible, but no success.

            Thanks for your help!

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

              hi
              ok. so its not because the timer call the render functions while a setpos is already in progress.

              Have you tried with other function besides setPos to find out if only for such operation?

              Also, is there any chance you cause infinite repaints, like calling setpos in paint so paint is called again. ?

              1 Reply Last reply
              1
              • M Mehonidas

                Hi all,
                i have trouble with my code.

                I have a class it inherit from QGraphicsItem and it update the position.
                I call the function render() in a gameloop (ca. 30 times a second). If i do this
                i got the runtimeerror "The program has unexpectedly finished." If i set the Position in the constructor
                it works, but i need to update it frequently.

                void Particle::render()
                {
                     setPos(position.getX(),position.getY());
                }
                

                How can i update the Position frequently.

                I hope the question is not too simple.
                THX for help!
                Greetings Meho

                A Offline
                A Offline
                Asperamanca
                wrote on last edited by
                #7

                @Mehonidas
                Two ideas:

                1. Any possibility you accidentally destroyed the item, and setPos is called on a destroyed object? Check by setting a breakpoint in your Item's destructor
                2. Is the timer running in the application's main thread?
                1 Reply Last reply
                1
                • M Offline
                  M Offline
                  Mehonidas
                  wrote on last edited by
                  #8

                  Hi,
                  thank you for your help!

                  I uploaded my code:
                  https://mega.nz/#!5EF12RKA!LkoWvUF4ABpB6XcMrk1qFWWw4OtzbnUxarWgUqGEg4g
                  I am a beginner, so please dont hit me for my bad code style!

                  Have you tried with other function besides setPos to find out if only for such operation?

                  The function setPos() works fine in the constructor of the class, but not in any other function.
                  I called the function with the key T, but the programm crashed too!

                  Also, is there any chance you cause infinite repaints, like calling setpos in paint so paint is called again. ?

                  I implemented the paint function but i use the setPos() function only at one position in the class!

                  Any possibility you accidentally destroyed the item, and setPos is called on a destroyed object?
                  Check by setting a breakpoint in your Item's destructor

                  No the destructor of class Particle is not called!

                  Is the timer running in the application's main thread?

                  I have only two threads:
                  QXcbEventReader-Thread
                  Bomberman-Thread
                  and the loopTimer (gameloop) is running in Bomberman-Thread (programm thread)

                  Thank you for your help!
                  Has somebody any other idea?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mehonidas
                    wrote on last edited by
                    #9

                    AHHHH,

                    OK i found the mistake!
                    It is so embarrassing!

                    I created 1000 particles for a particle system and put it in a list, for better handling.
                    In a function i use a for-loop to iterate about the list and call the render function of each particle. I began at 0 and used the "<=" statement. I iterated one step too much!

                    I confused that the debugger stopped at the setPos() function, so i searched the mistake at the wrong position!

                    Thank you very much for your help and time!
                    Bye Meho

                    1 Reply Last reply
                    0
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hehe good found :)

                      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