[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] subtel problem with event handler when disconnect -
From:       Grégory_Starck <g.starck () gmail ! com>
Date:       2011-10-12 14:10:14
Message-ID: CAM8fmGASfdB28+X=8oBWZcZjdyzJAqsjVpUAb8rSZxNkPuKjog () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


hi,

thx for the info.

regards,

greg.


2011/10/12 Doug Bell <dougb@bellz.org>

> Gr=E9gory Starck wrote:
> > Hi dear list,
> >
> > on windows7-64, with python32 (and also with python27) (-x86) and
> > pyqt-4.8.5-1:
> >
> > First of all: I'm quite new with Qt (pyqt).. and so I don't know all
> > of it, even more specifically about the restrictions/exceptions/etc..,
> > from far.
> >
> > in a quite simple window (just a tableWidget and few buttons
> > basically) :
> >
> > I connected the itemChanged signal/event of the tableWidget to one of
> > my method.  ( gui.tableWidget.itemChanged.connect(self.onCellChanged)
> > )
> >
> > but in this method I want to be able to eventually re-modify the value
> > of the item (depending on some conditions)..
> >
> > but doing so re-generate a itemChanged event..  so in that case my
> > method was called 1 extra time that I don't want.
> >
> > I used to work around that by : on begin of my method : I disconnect
> > the event itemChanged from my method. And on exit of my method I
> > re-connect the signal to it.
> >
> > my question is : does it sound like all right to you ??
> >
> > because with that I sometimes (but quite highly reproducible) get real
> > crash from QtCore.. but without any valuable detail.   as far as I
> > understood : it could be a problem because I disconnect-reconnect the
> > event handler from within the handler itself AND ALSO, apparently,
> > that I was also displaying a QtGui.QMessageBox  from within my method.
> > (when I remove the display of the Qmsgbox then the crash doesn't occur
> > anymore, never, as far I could see).
> >
> > Now I've totally work around the problem/crash by using a bool flag
> > that I initially set to False.  when my itemChanged event handler
> > enters : it checks for the flag. if True -> the method directly
> > returns. Else it sets the flag to True and the method executes
> > normally. before returning from it I reset the flag to False.  So that
> > if I change the value of the item in the method then the method will
> > still be called 1 extra time but I notice it thx to the flag.
>
> A cleaner way to do this is to use widget.blockSignals(True) before
> re-modifying the value and then widget.blockSignals(False) afterward.
>
> -Doug
> _______________________________________________
> PyQt mailing list    PyQt@riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

[Attachment #5 (text/html)]

hi,<div><br></div><div>thx for the \
info.<div><br></div><div>regards,</div><div><br></div><div>greg.</div><div><br><br><div \
class="gmail_quote">2011/10/12 Doug Bell <span dir="ltr">&lt;<a \
href="mailto:dougb@bellz.org">dougb@bellz.org</a>&gt;</span><br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex;"><div><div></div><div class="h5">Grégory Starck wrote:<br> \
&gt; Hi dear list,<br> &gt;<br>
&gt; on windows7-64, with python32 (and also with python27) (-x86) and<br>
&gt; pyqt-4.8.5-1:<br>
&gt;<br>
&gt; First of all: I&#39;m quite new with Qt (pyqt).. and so I don&#39;t know all<br>
&gt; of it, even more specifically about the restrictions/exceptions/etc..,<br>
&gt; from far.<br>
&gt;<br>
&gt; in a quite simple window (just a tableWidget and few buttons<br>
&gt; basically) :<br>
&gt;<br>
&gt; I connected the itemChanged signal/event of the tableWidget to one of<br>
&gt; my method.  ( gui.tableWidget.itemChanged.connect(self.onCellChanged)<br>
&gt; )<br>
&gt;<br>
&gt; but in this method I want to be able to eventually re-modify the value<br>
&gt; of the item (depending on some conditions)..<br>
&gt;<br>
&gt; but doing so re-generate a itemChanged event..  so in that case my<br>
&gt; method was called 1 extra time that I don&#39;t want.<br>
&gt;<br>
&gt; I used to work around that by : on begin of my method : I disconnect<br>
&gt; the event itemChanged from my method. And on exit of my method I<br>
&gt; re-connect the signal to it.<br>
&gt;<br>
&gt; my question is : does it sound like all right to you ??<br>
&gt;<br>
&gt; because with that I sometimes (but quite highly reproducible) get real<br>
&gt; crash from QtCore.. but without any valuable detail.   as far as I<br>
&gt; understood : it could be a problem because I disconnect-reconnect the<br>
&gt; event handler from within the handler itself AND ALSO, apparently,<br>
&gt; that I was also displaying a QtGui.QMessageBox  from within my method.<br>
&gt; (when I remove the display of the Qmsgbox then the crash doesn&#39;t occur<br>
&gt; anymore, never, as far I could see).<br>
&gt;<br>
&gt; Now I&#39;ve totally work around the problem/crash by using a bool flag<br>
&gt; that I initially set to False.  when my itemChanged event handler<br>
&gt; enters : it checks for the flag. if True -&gt; the method directly<br>
&gt; returns. Else it sets the flag to True and the method executes<br>
&gt; normally. before returning from it I reset the flag to False.  So that<br>
&gt; if I change the value of the item in the method then the method will<br>
&gt; still be called 1 extra time but I notice it thx to the flag.<br>
<br>
</div></div>A cleaner way to do this is to use widget.blockSignals(True) before<br>
re-modifying the value and then widget.blockSignals(False) afterward.<br>
<br>
-Doug<br>
_______________________________________________<br>
PyQt mailing list    <a \
href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br> <a \
href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" \
target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br> \
</blockquote></div><br></div></div>



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic