[PyKDE] pyqt4: segmentation fault/data corruption with signal/slots

Andreas Pakulat apaku at gmx.de
Fri Sep 22 12:53:02 BST 2006


On 22.09.06 02:01:06, Panard wrote:
> I'm experiencing a strange problem with PyQt4.
> - PyQt4 and Sip snapshots 20060917
> - qt-4.1.4
> - all compiled with gcc 4.1.1
> 
> My test case is a QDialog, designed with designer, which contains only a 
> QProgressBar.
> That QDialog (progress_section) will start a thread which will do some stuff 
> and emit signals to the QDialog for notifying progress 
> (signal "section_changed").
> progress_section connects the signal "section_changed" to a test method, which 
> will print the arguments of the emit ( a string and a float ).
> 
> But when printing those arguments, it appears that the values of them has 
> changed... and some strange things are printed :
> ==> emit Read available updates 0.2
> receive (<refcnt 0 at 0x2b94aca3bef0>, <refcnt 0 at 0x2b94a9377500>) <frame 
> object at 0x752810>
> or 
> receive (<refcnt 0 at 0x2abf8db795a8>, <bound method job.start of 
> <job(Thread-1, stopped)>>) <refcnt 2377570436 at 0x2abf8db6d8b8>
> 
> In my qt app where I extracted that test case, things like
>  (<refcnt 0 at 0x10a1e18>, 'Python-urllib/2.4') Python-urllib/2.4
> appear... looks like information leak!

No, not an information leak. Just plain wrong usage of threads. The
QDialog runs in the main - the gui - thread and you cannot safely call
any of it's methods from outside that thread. But that is exactly what
you do, you call on_success of the dialog.

Also I don't think python threads mix very well with Qt code, please
first try QThread for threading purposes. And for communication either
use Qt::QueuedConnection with signals/slots across threads or use plain
old events that you post from one thread to the other.

Andreas

-- 
People are beginning to notice you.  Try dressing before you leave the house.




More information about the PyQt mailing list