[PyQt] signal-slot connect problem

Phil Thompson phil at riverbankcomputing.co.uk
Wed Jan 9 08:51:15 GMT 2008


On Wednesday 09 January 2008, David Douard wrote:
> On Tue, Jan 08, 2008 at 05:26:53PM +0000, Phil Thompson wrote:
> > On Tuesday 08 January 2008, Martin Höfling wrote:
> > > Hi all,
> > >
> > > I am trying to create a filter Toolbar bar class, filtering a model.
> > >
> > > why does the following connect command  in the loadModel Method not
> > > work?:
> > >
> > > class FilterToolBar(QToolBar):
> > >     def __init__(self):
> > >         super(FilterToolBar,self).__init__(QString("Filter"))
> > >         self.expFilterCombo=QComboBox()
> > >         self.projFilterCombo=QComboBox()
> > >         self.expFilterCombo.setVisible(True)
> > >         self.projFilterCombo.setVisible(True)
> > >         self.addWidget(self.expFilterCombo)
> > >         self.addWidget(self.projFilterCombo)
> > >         self.expFilterCombo.setEditable(True)
> > >         self.projFilterCombo.setEditable(True)
> > >
> > >     def loadModel(self,  proxymdl1,  proxymdl2, model):
> > >         self.proxymdlexp=proxymdl1
> > >         self.proxymdlproj=proxymdl2
> > >         self.expFilterCombo.clear()
> > >         self.projFilterCombo.clear()
> > >         self.expFilterCombo.clearEditText()
> > >         self.projFilterCombo.clearEditText()
> > >         exps=model.experiments.keys()
> > >         projs=model.projects.keys()
> > >         addToComboBox(exps, self.expFilterCombo)
> > >         addToComboBox(projs, self.projFilterCombo)
> > >
> > > #problem section start
> > >         self.connect(self.expFilterCombo, SIGNAL("editTextChanged()"),
> > > self.expFilterChanged)
> > >         self.connect(self.projFilterCombo, SIGNAL("editTextChanged()"),
> > > self.projFilterChanged)
> > > #problem section stop
> > >
> > >     def expFilterChanged(self):
> > >        print "Filter Exp update"
> > >
> > > self.proxymdlexp.setFilterFixedString(self.expFilterCombo.itemText())
> > > self.proxymdlexp.setFilterKeyColumn(EXPERIMENT)
> > >
> > >     def projFilterChanged(self):
> > >        print "Filter Proj update"
> > >
> > > self.proxymdlproj.setFilterFixedString(self.projFilterCombo.itemText())
> > > self.proxymdlproj.setFilterKeyColumn(PROJECT)
> > >
> > > The filter toolbar is created on startup and the loadModel Method is
> > > called when a new model has been loaded. Nothing happens if i change
> > > the text.
> >
> > Because there is no signal with that signature - you've missed out the
> > argument type.
>
> This makes me think: would'nt be possible to display a warning message
> (or to add a flag somewhere which would activate this feature) when
> pyqt detects a wrong signature in SIGNAL ?
>
> I know this would break (so the idea of the flag) the easy way of
> SIGNAL/SLOT in pure python (as a -- positive in my mind -- side
> effect, people would be more incitated to use the pyQtSignature in
> python code).
>
> I mean it is a very common mistake, even for advanced PyQt developers,

Is it?

> and it is not always easy to track. It could at least save sometimes
> one hour or two to many PyQt developpers, I guess ;-)

The problem is that they are indistinguishable from Python signals which don't 
need to be pre-defined.

Phil



More information about the PyQt mailing list