Re: [PyQt] Strange behavior with new-style signals and slots

2012-04-02 Thread michael h
 Message: 1
 Date: Sun, 01 Apr 2012 13:04:30 +0200
 From: Detlev Offenbach det...@die-offenbachs.de
 To: pyqt@riverbankcomputing.com
 Subject: [PyQt] Strange behavior with new-style signals and slots
 Message-ID: 1362374.ZZnnlU3EYs@jupiter
 Content-Type: text/plain; charset=us-ascii

 Hallo,

 I am observing a strange behavior related to new-style signal and slots.
 Here
 is the situation.

 My program calls this line twice in a class (via different code paths).


 self.project.projectPropertiesChanged.connect(self.__projectPropertiesChanged)

 The disconnect is only issued once when the class (the editor) is closed.


 self.project.projectPropertiesChanged.disconnect(self.__projectPropertiesChanged)

 If the signal is emitted thereafter, I get a RuntimeError saying, that the
 underlying C/C++ object has been destroyed. I suspect, that the Python
 wrapper
 for the Qt object (here it is a QScintilla object) is still kept alive by
 some
 reference counter (possibly caused by the double connection).

 Is this a bug in PyQt/sip or do I have to avoid such a situation? If the
 later
 is the case, is it possible to check, if a signal is already connected,
 e.g.
 something like


 self.project.projectPropertiesChanged.is_connected(self.__projectPropertiesChanged)

 Another consequence of the double connection is, that the slot is called
 twice
 when the signal is emitted.

 Regards,
 Detlev
 --
 Detlev Offenbach
 det...@die-offenbachs.de


Detlev,

Perhaps you want to make use of Qt::UniqueConnection as the connection type.

Note that I believe this will only work correctly on a slot decorated with
pyqtSlot (or that was previously the case anyhow)

- MH
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] Strange behavior with new-style signals and slots

2012-04-01 Thread Detlev Offenbach
Hallo,

I am observing a strange behavior related to new-style signal and slots. Here 
is the situation.

My program calls this line twice in a class (via different code paths).

self.project.projectPropertiesChanged.connect(self.__projectPropertiesChanged)

The disconnect is only issued once when the class (the editor) is closed.

self.project.projectPropertiesChanged.disconnect(self.__projectPropertiesChanged)

If the signal is emitted thereafter, I get a RuntimeError saying, that the 
underlying C/C++ object has been destroyed. I suspect, that the Python wrapper 
for the Qt object (here it is a QScintilla object) is still kept alive by some 
reference counter (possibly caused by the double connection).

Is this a bug in PyQt/sip or do I have to avoid such a situation? If the later 
is the case, is it possible to check, if a signal is already connected, e.g. 
something like

self.project.projectPropertiesChanged.is_connected(self.__projectPropertiesChanged)

Another consequence of the double connection is, that the slot is called twice 
when the signal is emitted.

Regards,
Detlev
-- 
Detlev Offenbach
det...@die-offenbachs.de
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Strange behavior with new-style signals and slots

2012-04-01 Thread Phil Thompson
On Sun, 01 Apr 2012 13:04:30 +0200, Detlev Offenbach
det...@die-offenbachs.de wrote:
 Hallo,
 
 I am observing a strange behavior related to new-style signal and slots.
 Here 
 is the situation.
 
 My program calls this line twice in a class (via different code paths).
 

self.project.projectPropertiesChanged.connect(self.__projectPropertiesChanged)
 
 The disconnect is only issued once when the class (the editor) is
closed.
 

self.project.projectPropertiesChanged.disconnect(self.__projectPropertiesChanged)
 
 If the signal is emitted thereafter, I get a RuntimeError saying, that
the 
 underlying C/C++ object has been destroyed. I suspect, that the Python
 wrapper 
 for the Qt object (here it is a QScintilla object) is still kept alive
by
 some 
 reference counter (possibly caused by the double connection).
 
 Is this a bug in PyQt/sip or do I have to avoid such a situation?

I can't tell from your description - you need to provide a test case.
Making the same connection twice is technically possible, but sounds like
an application bug to me.

 If the
 later 
 is the case, is it possible to check, if a signal is already connected,
 e.g. 
 something like
 

self.project.projectPropertiesChanged.is_connected(self.__projectPropertiesChanged)
 
 Another consequence of the double connection is, that the slot is called
 twice 
 when the signal is emitted.

...which is what you would expect.

Phil
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt