[PyQt] Conflict between setuptools & requirements in official PyQt5 docs

Phil Thompson phil at riverbankcomputing.com
Wed Feb 10 18:44:59 GMT 2016


On 10 Feb 2016, at 6:08 pm, Baz Walter <bazwal at ftml.net> wrote:
> 
> On 10/02/16 17:24, Phil Thompson wrote:
>> On 10 Feb 2016, at 4:49 pm, Jones, Bryan <bjones at ece.msstate.edu> wrote:
>>> 
>>> def printDestroyed(qObject):
>>>     def destroyed():
>>>         print('destroyed {}'.format(qObject))
>>>     qObject.destroyed.connect(destroyed)
>>> 
>>> def qtMain():
>>>     global app
>>>     app = QApplication(sys.argv)
>>>     printDestroyed(app)
>>> 
>>>     w = QWidget()
>>>     printDestroyed(w)
>>>     w.show()
>>> 
>>> def gcCrash():
>>>     print('gcCrash')
>>>     qtMain()
>>>     gc.collect()
>> 
>> I think that has something to do with the destroyed() slot being in a
>> nested function. Also the destroyed signal can be tricky to deal with
>> because it is emitted during the destruction of the QObject. I'm not
>> saying there isn't a bug here, but I'm not sure it's a symptom of the
>> crash on exit issue.
>> 
>> Phil
> 
> This example can be made a bit clearer if the widget is explicitly deleted like this:
> 
>    w = QWidget()
>    w.setAttribute(Qt.WA_DeleteOnClose, True)
>    printDestroyed(w)
>    w.show()
> 
> The destroyed signal is now emitted, but it produces a somewhat unexpected exception:
> 
>    NameError: free variable 'qObject' referenced before assignment in enclosing scope
> 
> This can be fixed by avoiding use of the enclosed variable in the nested function:
> 
> def printDestroyed(qObject):
>    def destroyed(obj):
>        print('destroyed {}'.format(obj))
>    qObject.destroyed.connect(destroyed)
> 
> Which works okay, but still dumps core on exit, which I don't understand. Any ideas why that is?

With your changes it works fine for me (on OSX), no crash on exit.

Phil


More information about the PyQt mailing list