On Sunday 12 December 2010 22:26:57 [email protected] wrote:
> Hi,
> 
> the documentation of how to use new style signals and slots is relatively
> sparse, thus I wrote some test cases to determine what is to expect. I was
> mostly looking at PyQt4 documentation when working with new style signals
> and slots. These test cases raised two questions:
> 
> 1) Even if a slot was annotated with @Slot(type) the connection is made
> with all signals of the same name and not just the signal with the correct
> overload type. The PyQt documentation states that it is using a default
> overload in these situations. What is the right behavior in this case?
> 
>     @QtCore.Slot(int)
>     @QtCore.Slot('double')
>     @QtCore.Slot(str)
>     @QtCore.Slot('QVariant')
>     def slot1(self, value1):
>         self._value1 = value1
> 
>     @QtCore.Slot(int)
>     def slot1Int(self, value1):
>         self._value1Int = value1
> 
>     def testAutomaticType(self):
>         spinBox = QtGui.QSpinBox()
>         spinBox.valueChanged.connect(self.slot1Int)
>         spinBox.valueChanged.emit(1)
>         self.assertEqual(1, self._value1Int)

As discussed in this mailing list you can't rely on the default signal, 
because it's chosen by PySide according to the order it appear on Qt headers 
and if Qt add another overload for a signal your program can break :-/.

> 2) float is no valid type for double signals, although a Python float is a
> C signed double. Should the Python type float be a valid type for signal
> overrides?
> 
>     def testDoubleSignal2(self):
>         spinBox = QtGui.QDoubleSpinBox()
>         spinBox.valueChanged[float].connect(self.slot1)
>         spinBox.valueChanged[float].emit(2.0)
>         self.assertEqual(2.0, self._value1)

Should be, all python primitives should be valid types for signals and slots.

> The testPartial and testLambda methods are test cases for bug #542. In the
> case of the clicked signal of a QPushButton, the optional signal parameter
> "checked = false" seems to get passed along to slots that are partial or
> lambda functions.

Can you send to us your unit test? so we can check the failing tests and maybe 
add it to our test suite.

> Test output
> -----------
> 
> Finding files...
> ['/.../new_style_signals_slots.py'] ... done
> Importing test modules ... done.
> 
> testAutomaticSignalType
> (new_style_signals_slots.NewSignalsAndSlotsTestCase) ... FAIL
> testDoubleSignal1 (new_style_signals_slots.NewSignalsAndSlotsTestCase) ...
> ok testDoubleSignal2 (new_style_signals_slots.NewSignalsAndSlotsTestCase)
> ... ERROR testIntSignal1
> (new_style_signals_slots.NewSignalsAndSlotsTestCase) ... ok testIntSignal2
> (new_style_signals_slots.NewSignalsAndSlotsTestCase) ... ok testLambda
> (new_style_signals_slots.NewSignalsAndSlotsTestCase) ... FAIL
> testMultiParameters (new_style_signals_slots.NewSignalsAndSlotsTestCase)
> ... ok testPartial (new_style_signals_slots.NewSignalsAndSlotsTestCase)
> ... FAIL TypeErrortestPythonSignal
> (new_style_signals_slots.NewSignalsAndSlotsTestCase) ... ok testStrSignal1
> (new_style_signals_slots.NewSignalsAndSlotsTestCase) ... ok testStrSignal2
> (new_style_signals_slots.NewSignalsAndSlotsTestCase) ... : slot1() takes
> exactly 2 arguments (3 given) ok
> testStrSignal3 (new_style_signals_slots.NewSignalsAndSlotsTestCase) ... ok
> 
> ======================================================================
> ERROR: testDoubleSignal2
> (new_style_signals_slots.NewSignalsAndSlotsTestCase)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/.../new_style_signals_slots.py", line 105, in testDoubleSignal2
>     spinBox.valueChanged[float].connect(self.slot1)
> IndexError: Signature valueChanged(qreal) not found for signal:
> valueChanged
> 
> ======================================================================
> FAIL: testAutomaticSignalType
> (new_style_signals_slots.NewSignalsAndSlotsTestCase)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/.../new_style_signals_slots.py", line 65, in
> testAutomaticSignalType self.assertEqual(1, self._value1Int)
> AssertionError: 1 != u''
> 
> ======================================================================
> FAIL: testLambda (new_style_signals_slots.NewSignalsAndSlotsTestCase)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/.../new_style_signals_slots.py", line 114, in testLambda
>     self.assertEqual('Button', self._value1)
> AssertionError: 'Button' != True
> 
> ======================================================================
> FAIL: testPartial (new_style_signals_slots.NewSignalsAndSlotsTestCase)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/.../new_style_signals_slots.py", line 121, in testPartial
>     self.assertEqual('Button', self._value1)
> AssertionError: 'Button' != None
> 
> ----------------------------------------------------------------------
> Ran 12 tests in 0.013s
> 
> FAILED (failures=3, errors=1)
> 
> 
> The test cases are attached.

-- 
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to