-2

Based on SO question and answer given here I modified the answer where the value becomes a list. It throws me an error.

Is it possible that the value is in fact a list with values? Like value=[1,2,3]? In this case the list represents a tabWidget index positions at three levels in the GUI... Or is this handled differently? All/Other suggestions are welcome.

Traceback error:

createAction
    self.tabindex.valueChanged.connect(self.do_something)
AttributeError: 'list' object has no attribute 'valueChanged'

The code:

class Foo(QWidget):

    valueChanged = pyqtSignal(object)

    def __init__(self, parent=None):
        super(Foo, self).__init__(parent)
        self._t = [1,2,3]

    @property
    def t(self):
        return self._t

    @t.setter
    def t(self, list):
        self._t = list
        self.valueChanged.emit(list)

    def createAction(self):
        self.t.valueChanged.connect(self.do_something)

    def do_something(self):
        ...
        print('show something here')        
ZF007
  • 3,708
  • 8
  • 29
  • 48
  • 1
    `valueChanged` is a signal of `Foo` itself, so you should do `self.valueChanged.connect(self.do_something)`. The value that should be emitted with the signal is determined when the signal is emitted, not when connecting the signal to a slot. – Heike May 09 '20 at 11:58
  • Thanks for the explanation and your solution fixed it. If you can post it as answer I can rep-wise reward it and it clears it from the unsolved question list ;-) – ZF007 May 09 '20 at 12:05
  • I've added my comment as an answer – Heike May 09 '20 at 12:10

1 Answers1

1

valueChanged is a signal of Foo itself, so you should use self.valueChanged.connect(self.do_something) instead of self.t.valueChanged.connect(self.do_something). After all, the value that should be emitted with the signal is determined when the signal is emitted, not when connecting the signal to a slot.

Heike
  • 24,102
  • 2
  • 31
  • 45