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. Application Crash if sending very fast to QApplication::instance()->postEvent

Application Crash if sending very fast to QApplication::instance()->postEvent

Scheduled Pinned Locked Moved General and Desktop
crashposteventmultithreads
13 Posts 3 Posters 8.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.
  • J Offline
    J Offline
    jsulm
    Lifetime Qt Champion
    wrote on 20 Oct 2015, 06:28 last edited by
    #4

    Why do you want to send events to focused widget? What if another widget gets focus?
    And why don't you use signals/slots?
    Are you sure you need multi-threading? You can do TCP communication asynchronously in Qt.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • B Offline
      B Offline
      BluTiGeS
      wrote on 20 Oct 2015, 07:16 last edited by
      #5

      Hi,

      the architecture is needed because we are running multiple applications which communicate with each other.
      I also did the same implementation using a signal/slot approach but it also crashes if it gets under high load.

      The background of this is to simulate user interaction by sending a XML command to the Main Application which then calls the QT part.

      If i put a sleep of 1 sec after posting the events it works , so I am wondering why it crashes if it gets fast events.

      It seems to process handling crashes on fast calls (50-100 events a sec).

      Many Thanks

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 20 Oct 2015, 09:35 last edited by
        #6

        Where exactly does your application crash?
        Maybe you just have an synchronisation issue in your code since you use multi-threading.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BluTiGeS
          wrote on 20 Oct 2015, 10:01 last edited by
          #7

          Hi,
          I narrowed it down that it crash during postEvent call.

          If i comment the postEvent out all works fine. Also If I set a sleep from 500 ms it works.

          Maybe the other application sends too fast the events that qt does not have time to handle them and then crashes?

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 20 Oct 2015, 11:26 last edited by
            #8

            Are you sure it is the postEvent call itself and not the code which is triggered by postEvent?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • B Offline
              B Offline
              BluTiGeS
              wrote on 20 Oct 2015, 11:52 last edited by
              #9

              I am just sending to the focused widget, already checking if the focus is set

              if( focus )
              

              or do you mean it could occur that the focused widget is not available anymore during the postEvent?

              how to prevent this?

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 20 Oct 2015, 12:30 last edited by
                #10

                I mean do you have any code which is executed when you call postEvent? So, do you have any event handlers?
                Yes it can happen that after if(focus) focus is not valid any more. This is one of the problem you can get in multi-threaded applications.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  BluTiGeS
                  wrote on 21 Oct 2015, 06:55 last edited by
                  #11

                  Hi,

                  I just let the GUI handle the event .
                  For example if a button is focused and it gets the event for pressing the key the screen will change to a different widget. Or if left right is posted by the events the focus will move in the widget to a different button.

                  But the events are handled in the widgets themselves then, so no bypass done here just normal Qt implementation with Signal and Slots.

                  Regards

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 21 Oct 2015, 07:04 last edited by
                    #12

                    Since you are running several applications, why not use IPC in your design ? That way you wouldn't need to do hacks to communicate between them

                    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
                    • B Offline
                      B Offline
                      BluTiGeS
                      wrote on 22 Oct 2015, 11:55 last edited by
                      #13

                      Many thanks for all your help,

                      I now switched from postEvent to sendEvent, so it is not like fire and forget and I can handle the returns.

                      Also now I can fire a lot of sendEvents and no crash appears anymore. So this solves it for me.

                      Regards

                      1 Reply Last reply
                      0

                      13/13

                      22 Oct 2015, 11:55

                      • Login

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