Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. PySide QEvent post crash
Forum Updated to NodeBB v4.3 + New Features

PySide QEvent post crash

Scheduled Pinned Locked Moved Language Bindings
2 Posts 2 Posters 1.8k Views 1 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.
  • P Offline
    P Offline
    Pierre_
    wrote on last edited by
    #1

    Hello everyone,

    I'm working on Linux Ubuntu 12.10, with PySide 1.1.1 and python 2.7
    I have a problem when posting QEvent through a QStateMachine.

    If I want it to work I have to keep a reference on the event, or it crashes.
    I have set up a little sample code to illustrate my problem.

    I would like to know if I am doing it wrong or if it is a known problem and if I should use the workaround (keeping a reference on the event) ?

    @
    #!/usr/bin/python

    from future import print_function
    import sys
    from PySide.QtCore import *
    from PySide.QtGui import *

    app = QApplication(sys.argv)
    sm = QStateMachine()
    init = QState(sm)
    sm.setInitialState(init)
    sm.start()

    e = None
    def no_crash():
    global e
    print("send an event that doesn't crash...")
    e = QEvent(QEvent.Type(QEvent.registerEventType()))
    sm.postEvent(e)

    def crash():
    print("and one that does...")
    e = QEvent(QEvent.Type(QEvent.registerEventType()))
    sm.postEvent(e)

    QTimer.singleShot(2000, no_crash)
    QTimer.singleShot(4000, crash)

    sys.exit(app.exec_())
    @

    Thanks by advance for your help

    Pierre

    1 Reply Last reply
    0
    • I Offline
      I Offline
      istlota
      wrote on last edited by
      #2

      I initially ran into the same ugly crash when I was converting the 'Events, Transitions, and Guards' example from Qt Project's excellent State Machine Framework doc to PySide. Your global reference to the registered QEvent Type fixes the crash problem because it prevents python's automatic garbage collection from kicking in before you want it to.

      In my final code, rather than using a global reference which is inelegant, I wrap all the functionality into a QWidget which is used as the main window of the app. That allows me to save the registered QEvent as an instance variable in the QWidget's class constructor. The idea being that python knows not to garbage collect instance variables as long as the class instance itself is being used.

      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