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. Segfault after signal emit
Forum Updated to NodeBB v4.3 + New Features

Segfault after signal emit

Scheduled Pinned Locked Moved Language Bindings
4 Posts 2 Posters 3.5k 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.
  • A Offline
    A Offline
    abieler
    wrote on last edited by
    #1

    I am trying to switch from pyqt4 to pyside and having trouble when emitting a signal from a worker thread.
    the result is a segmentation fault. The same thing works for pyt4.
    the gui consists of one button which starts the worker thread and should emit a signal when done.
    the worker_thread is started after clicking the button, but the segfault appears when emitting the signal.
    (this is meant to be a generic example, not (yet) a useful application...)

    Thanks for the help!

    @
    import sys

    from PySide import QtCore as QTC
    from PySide import QtGui as QTG
    import ui_signalTest_pyside as myUi

    '''
    from PyQt4 import QtCore as QTC
    from PyQt4 import QtGui as QTG
    import ui_signalTest_pyqt as myUi
    '''

    class Window(QTG.QWidget,myUi.Ui_Form):
    def init(self, parent = None):
    super(Window, self).init(parent)
    self.setupUi(self)

        self.worker_thread = Worker()
        self.connect(self.worker_thread,QTC.SIGNAL("doSomething"),\
        self.myFunc)
        self.connect(self.pushButton, QTC.SIGNAL("clicked()"),\
        self.startThread)
    
    
    def startThread(self):
        self.worker_thread.start()
    
    
    def myFunc(self,msg):
        print 'signal recieved:', msg
    

    class Worker(QTC.QThread):

    def __init__(self, parent = None):
        QTC.QThread.__init__(self,parent)
    
    
    def run(self):
        N = 10000
        for i in range(N):
            for j in range(N):
                i+j
    
        msg = 'loop finished'
        self.emit(QTC.SIGNAL("doSomething"),msg)
    

    app = QTG.QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())

    @

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lcasassa
      wrote on last edited by
      #2

      I am having the same problem, did you find a solution? Thanks.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        abieler
        wrote on last edited by
        #3

        yes i did find a solution:
        @
        import sys

        from PySide import QtCore as QTC
        from PySide import QtGui as QTG
        import ui_signalTest_pyside as myUi

        '''
        from PyQt4 import QtCore as QTC
        from PyQt4 import QtGui as QTG
        import ui_signalTest_pyqt as myUi
        '''

        class Window(QTG.QWidget,myUi.Ui_Form):
        def init(self, parent = None):
        super(Window, self).init(parent)
        self.setupUi(self)

            self.worker_thread = Worker()
            self.connect(self.pushButton,QTC.SIGNAL("clicked()"),
                              self.startThread)
            
            self.worker_thread.mySignal.connect(self.myFunc,
                              QTC.Qt.QueuedConnection)
        
        def startThread(self):
            self.worker_thread.start()
        
        
        def myFunc(self,msg):
            print 'signal recieved:', msg
        

        class Worker(QTC.QThread):

        mySignal = QTC.Signal(str)
            
        def __init__(self, parent = None):
            QTC.QThread.__init__(self,parent)
        
        
        def run(self):
            N = 10000
            for i in range(N):
                for j in range(N):
                    i+j
        
            msg = 'loop finished'
            self.mySignal.emit(msg)
        

        app = QTG.QApplication(sys.argv)
        window = Window()
        window.show()
        sys.exit(app.exec_())
        @

        1 Reply Last reply
        0
        • A Offline
          A Offline
          abieler
          wrote on last edited by
          #4

          It would be good if someone more knowledgeable than me could comment on my first attempt that ends in a segfault. is this a bug in pyside or is it not intended to be used like that?

          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