[PyKDE] Strange problem with signal/slot

Phil Thompson phil at riverbankcomputing.co.uk
Sat Jan 28 23:05:59 GMT 2006


On Saturday 28 January 2006 9:25 pm, Thomas Muders wrote:
> Hi List,
>
> i've used PyQt3 before and now I'm getting started with PyQt4. I'm
> interested in the Interview (Model/View) framework and so I have been
> "porting" a C++ tutorial using Interview to PyQt. I'm using the
> 20060126 version with Qt 4.1.0 under Linux as the 20060127 version
> didn't work.
> I've a strange problem with emit:
> in a subclass of QAbstractItemModel I have the following code in the
> method set Data:
>
>     def setData(self, idx, value, role):
>  [...]
>         if ok:
>             self.emit(SIGNAL("dataChanged(QModelIndex&,QModelIndex&)"),
> (idx,idx))
>             curExpense.convertedAmount = curExpense.originalAmount * \
>                curExpense.conversionRate
>             cellIndex = self.index(idx.row(), ConvertedAmount,
> QModelIndex()) self.emit(SIGNAL("dataChanged(QModelIndex&,QModelIndex&)"),
> (cellIndex,cellIndex))
>         return ok
>
> OK is a bool, which is the required return type for the function. If I
> don't have the emit's, everything is OK. When the emit's are there
> like in the sample, I get the following error on the console:
> TypeError: invalid result type from ExpenseModel.setData()
>
> I verified with print that the type of ok is in fact bool, so there is
> no problem (anyway without emit it works)
>
> is this a bug in PyQt or a misunderstanding?

emit() behaves differently in PyQt4. It takes a variable number of arguments, 
the first is the signal and the remaining ones are the signal arguments. In 
PyQt3 it took two arguments - the second being a tuple of the signal 
arguments. Drop the brackets around the signal arguments.

Phil




More information about the PyQt mailing list