[Tutor] PyQt segfault

Tiago Saboga tiagosaboga at terra.com.br
Fri Nov 30 15:14:05 CET 2007


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.

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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cbox.py
Type: text/x-python
Size: 1510 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20071130/2f907f59/attachment.py 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: comboboxsegfault.py
Type: text/x-python
Size: 1651 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20071130/2f907f59/attachment-0001.py 
-------------- next part --------------
<ui version="4.0" >
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog" >
  <property name="geometry" >
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
   </rect>
  </property>
  <property name="windowTitle" >
   <string>Dialog</string>
  </property>
  <widget class="QDialogButtonBox" name="buttonBox" >
   <property name="geometry" >
    <rect>
     <x>30</x>
     <y>240</y>
     <width>341</width>
     <height>32</height>
    </rect>
   </property>
   <property name="orientation" >
    <enum>Qt::Horizontal</enum>
   </property>
   <property name="standardButtons" >
    <set>QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
   </property>
  </widget>
  <widget class="QComboBox" name="comboBox" >
   <property name="geometry" >
    <rect>
     <x>60</x>
     <y>30</y>
     <width>231</width>
     <height>31</height>
    </rect>
   </property>
   <item>
    <property name="text" >
     <string>First</string>
    </property>
   </item>
   <item>
    <property name="text" >
     <string>Second</string>
    </property>
   </item>
  </widget>
 </widget>
 <resources/>
 <connections>
  <connection>
   <sender>buttonBox</sender>
   <signal>accepted()</signal>
   <receiver>Dialog</receiver>
   <slot>accept()</slot>
   <hints>
    <hint type="sourcelabel" >
     <x>248</x>
     <y>254</y>
    </hint>
    <hint type="destinationlabel" >
     <x>157</x>
     <y>274</y>
    </hint>
   </hints>
  </connection>
  <connection>
   <sender>buttonBox</sender>
   <signal>rejected()</signal>
   <receiver>Dialog</receiver>
   <slot>reject()</slot>
   <hints>
    <hint type="sourcelabel" >
     <x>316</x>
     <y>260</y>
    </hint>
    <hint type="destinationlabel" >
     <x>286</x>
     <y>274</y>
    </hint>
   </hints>
  </connection>
 </connections>
</ui>


More information about the Tutor mailing list