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" <[EMAIL PROTECTED]> 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.
#!/usr/bin/python2.5
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
from comboboxsegfault import Ui_Dialog
import sys
class Globals:
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)
self.connect(self, QtCore.SIGNAL("finished(int)"),
self.finish)
def save(self, qstring):
# With a unicode invocation here it works:
#Aux.mystring = unicode(qstring)
Globals.changedtext = qstring
def finish(self):
Globals.currenttext = self.ui.comboBox.currentText()
def main(args):
app = QtGui.QApplication(args)
win = Combobox()
win.show()
app.exec_()
print "Constructed with QString: %s" % Globals.qst
print "Constructed with QApp.translate: %s" % Globals.qtr
print "Got from combobox.currentText(): %s" % Globals.currenttext
try:
print "Passed by combobox activated() signal: %s" % Globals.changedtext
except AttributeError:
print "Change the choice in combobox to trigger the segfault."
def compare(args):
Globals.qst = QtCore.QString("Second")
Globals.qtr = QtGui.QApplication.translate("Dialog", "Second",
None, QtGui.QApplication.UnicodeUTF8)
if __name__=='__main__':
compare(sys.argv)
main(sys.argv)
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'comboboxsegfault.ui'
#
# Created: Fri Nov 30 11:55:12 2007
# by: PyQt4 UI code generator 4.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(QtCore.QSize(QtCore.QRect(0,0,400,300).size()).expandedTo(Dialog.minimumSizeHint()))
self.buttonBox = QtGui.QDialogButtonBox(Dialog)
self.buttonBox.setGeometry(QtCore.QRect(30,240,341,32))
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.NoButton|QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox")
self.comboBox = QtGui.QComboBox(Dialog)
self.comboBox.setGeometry(QtCore.QRect(60,30,231,31))
self.comboBox.setObjectName("comboBox")
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("accepted()"),Dialog.accept)
QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("rejected()"),Dialog.reject)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox.addItem(QtGui.QApplication.translate("Dialog", "First", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox.addItem(QtGui.QApplication.translate("Dialog", "Second", None, QtGui.QApplication.UnicodeUTF8))
<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>
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor