Qt connect and first connect or unicode
Oscar Benjamin
oscar.j.benjamin at gmail.com
Tue Sep 17 04:05:57 EDT 2013
On 17 September 2013 05:12, Mohsen Pahlevanzadeh
<mohsen at pahlevanzadeh.org> wrote:
> Dear all,
>
> Unfortunately, i confused and need help... the following code is:
> ###################################################
> ##CheckBox:
> QtCore.QObject.connect(self.checkBox,
> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> self.materialsInstance.setFilterDict("C",self,"name",self.lineEdit.text()))
>
> QtCore.QObject.connect(self.checkBox_2,
> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> self.materialsInstance.setFilterDict("C",self,"bought_price",persianToInteger(unicode(self.lineEdit_2.text()))))
>
> QtCore.QObject.connect(self.checkBox_4,
> QtCore.SIGNAL(_fromUtf8("toggled(bool)")), lambda:
> self.materialsInstance.setFilterDict("C",self,"stock",persianToInteger(unicode(self.lineEdit_3.text()))))
>
> ##LineEdit
> QtCore.QObject.connect(self.lineEdit,
> QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda:
> self.materialsInstance.setFilterDict("L",self,"name",self.lineEdit.text()))
>
> QtCore.QObject.connect(self.lineEdit_2,
> QtCore.SIGNAL(_fromUtf8("editingFinished()")), lambda:
> self.materialsInstance.setFilterDict("L",self,"bought_price",persianToInteger(unicode(self.lineEdit_2.text()))))
I don't really know what the problem you're having is but this code is
very difficult to read.
What's the point of the _fromUTF8 function? The strings you pass it
are all ASCII, so if you're trying to create unicode strings you could
just use the u prefix e.g. u"toggled(bool)".
Also you can avoid referring to the same deeply nested attributes by
importing them or assigning them to something first e.g.:
from QtCore import SIGNAL
from QtCore.QObject import connect # Not sure if QObject is a module...
## Checkbox:
setfilter = self.materialsInstance.setFilterDict
connect(self.checkBox, SIGNAL(u"toggled(bool)"),
lambda: setfilter("C", self, "name", self.lineEdit.text()))
Oscar
More information about the Python-list
mailing list