[PyQt] how to create object
David Boddie
davidb at met.no
Thu Oct 17 15:13:01 BST 2013
On Wed Oct 16 23:17:50 BST 2013, Mohsen Pahlevanzadeh wrote:
[...]
> and another file,(projectsFind.py) i have the following code:
> #################################################################3
> for key, val in
> self.projectsInstance.addOnFieldsInstance.items():
> instance = getattr(self,"%s" % val)
> print val
> #QtCore.QObject.connect(instance,
> QtCore.SIGNAL(_fromUtf8("stateChanged (int)")),
> #lambda:
> self.projectsInstance.setFilterDict_Find("TWCH",self,"addonfields",instance.CheckState(),instance))
> ######################################################################3
> I want to generate connect function accroding to numbers of obbjects.
> But i get the following traceback:
[...]
> File "/home/mohsen/codes/amlak/amlak/src/projectsFind.py", line 271,
> in setupUi
> instance = getattr(self,"%s" % val)
> AttributeError: 'Ui_ProjectsFind' object has no attribute
> '<PyQt4.QtGui.QCheckBox object at 0xa4abd64>'
I think you just need to use val as it is. It's a QCheckBox instance, so
you are converting the instance information to a string when you write
"%s" % val
As a result, getattr won't find the object you are looking for. Just connect
the signals of val to slots instead.
David
More information about the PyQt
mailing list