[Tutor] PyQt segfault

Eric Brunson brunson at brunson.com
Fri Nov 30 18:56:04 CET 2007


Tiago Saboga wrote:
> First, I just noticed I sent a non-working version of the code. The line
>
> print ("The same" if Aux.mystring==Aux.mystring2 else "Different")
>
> should be 
>
> print ("The same" if Aux.mystring==Aux.compare else "Different")
>
> Sorry for that.
>   

This comboboxsegfault.py doesn't seem to do anything on my box, but I 
did get an "MemoryError" and a stack trace when I ran cbox.py and 
changed the dropdown menu selection.

I changed the line:
        Globals.changedtext = qstring

to:
        Globals.changedtext = qstring[:]

to get a copy of qstring instead of a reference to it, and cbox.py seems 
to execute without problems now.  My guess is that the qstring is being 
disposed of when the dialog is torn down.

Just a guess, but you can research more to confirm or deny.

Hope that helps,
e.


> On Fri, Nov 30, 2007 at 01:13:39PM -0000, Alan Gauld wrote:
>   
>> "Tiago Saboga" <tiagosaboga at terra.com.br> wrote
>>     
>>> I am making a front-end to ffmpeg with pyqt and I am stuck in a
>>> segmentation fault I can't understand. I have written a little
>>>       
>>> def main(args):
>>>    app = QtGui.QApplication(args)
>>>    win = Combobox()
>>>    win.show()
>>>    app.exec_()
>>>
>>>    print type(Aux.mystring)
>>>    # If uncommented segfaults
>>>    # mystring = unicode(Aux.mystring)
>>>    print ("The same" if Aux.mystring==Aux.mystring2 else 
>>> "Different")
>>>       
>> It looks from this that it has nothing to do with Qt per se.
>> Does unicode() work OK outside of Qt?
>>     
>
> Not only outside of Qt, but even with a constructed QString. That's
> why I have put in the example the compare() function. It wasn't clear
> enough, but I have a segfault a few lines later:
>
>     print type(Aux.mystring)
>     # If uncommented segfaults
>     # mystring = unicode(Aux.mystring)
>     print ("The same" if Aux.mystring==Aux.mystring2 else "Different")
>     print Aux.compare                                                 
>     # segfault
>     print Aux.mystring
>
> Aux.compare is a QString constructed directly (QString("Second")) and
> Aux.mystring constructed read from ComboBox, but originally with the
> same string:
>
> self.comboBox.addItem(QtGui.QApplication.translate("Dialog", "Second",
> None, QtGui.QApplication.UnicodeUTF8))
>
> I have also tried constructing Aux.compare with
> QtGui.QApplication.translate, with the same args, and still no
> problems! 
>
>   
>> Or is Aux.mystring an insance of a QtString class that you need to
>> deference to get the real string that unicode will understand?
>>     
>
> Both Aux.mystring and Aux.compare have the same type,
> PyQt4.QtCore.QString.
>
>   
>> All I can think of, not knowing anything much of Qt.
>>     
>
> Thank you anyway. I am sending a new version of my test case attached,
> and I will try to run it in another machine to see if it's a local
> problem.
>
> Tiago.
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list