[Tutor] PyQt segfault

Tiago Saboga tiagosaboga at terra.com.br
Fri Nov 30 13:07:54 CET 2007


Hi!

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
dialogbox just to show the problem. I have already found a workaround,
commented out in the code, but I would like to know where is the
problem.

I am sending the pyuic-generated file in attachment, as well as ui file.

I am working in a debian/lenny system, with py 2.4 and 2.5.

cbox.py
=======

#!/usr/bin/python2.5
# -*- coding: utf-8 -*-

from PyQt4 import QtCore, QtGui
from comboboxsegfault import Ui_Dialog
import sys

class Aux:
    pass
    
class Combobox(QtGui.QDialog):
    def __init__(self):
        QtGui.QDialog.__init__(self)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
			
        self.connect(self.ui.comboBox, QtCore.SIGNAL("activated(QString)"),
                     self.save)
        def save(self, qstring):
	    # Here it works:
            #Aux.mystring = unicode(qstring)
	    Aux.mystring = qstring
					 
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")
    print Aux.compare
    # segfault
    print Aux.mystring
def compare(args):
    st = QtCore.QString("Second")
    Aux.compare = st
			
if __name__=='__main__':
    compare(sys.argv)
    main(sys.argv)

-------------- 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/1d27ea41/attachment.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