How does a PyQt Slot access a different class' object function? OO newbie confusion!



  • So I have a window class ui file that has all the buttons and functions that take care of the display..

    My application's .py file loads/instantiates the window class, but it also does non-gui type stuff and therefore has non-gui related objects.

    What I'd like to do, for example is whenever a button is pressed, the non-gui object's function gets called.

    Architecturally or syntaxically (?) how is this typically performed? Should the windows class inherit from these non-window type classes? I'm sure I can make the objects functions into global functions, but doesn't that defeat the OO spirit?


  • Lifetime Qt Champion

    Hi,

    You can follow more or less the same rules that would apply in C++ here.



  • Here's an example in case that's what you were looking for. self.someButton is a QPushButton, and self.someObject is the object with the onClick method that will be called when the signal is emitted.

    @
    self.someButton.clicked.connect(self.someObject.onClick)
    @



  • Thanks! That's what I as looking for!

    [quote author="elveatles" date="1406940916"]Here's an example in case that's what you were looking for. self.someButton is a QPushButton, and self.someObject is the object with the onClick method that will be called when the signal is emitted.

    @
    self.someButton.clicked.connect(self.someObject.onClick)
    @[/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.