[PyQt] converting old signal/slot to new signal/slot

c c coastalchaos at hotmail.co.uk
Thu May 28 08:03:08 BST 2015



The tutorial had a PyQt option. Click PyQt at the top of the code examples.

I do get the new style now thanks to your and other replies to the post.

I'm now wondering why adore application.instance() was the object as the parameter of the old style in my given example. 

Was it trying to make sure the signal was only connected to a slot in that instance of qcoreplication? As its not wrapped up I'm assuming there will be only one instance of it?

I've been going through the code and am running it, fixing a signal/slot error then running it again. Just working my way through, but I don't want to break what I already have. 

I'm trying to upgrade the code I have before moving forward with the rest of the project. 


Sent from my iPad

On 27 May 2015, at 20:32, "David Cortesi" <davecortesi at gmail.com> wrote:

> I'll try to clarify the new slot/signal style a bit, hopefully somebody else will fill in more.
> To start, just forget the old style entirely. A signal is a property of an object. It happens to have a method connect(). Thus
>     input_line = QLineEdit()
>     input_line.editingFinished.connect( self.accept_input_line )
> The argument to connect is an executable, typically self.some_method but often just a slot (i.e. method) on some other widget, as when you have an Edit menu with an Undo action, and you do
>     undo_action = my_edit_menu.addAction( QAction('Undo') )
>     undo_action.triggered.connect( my_plain_text_editor.undo )
> (The "slot' executable can even be a lambda! Which is sometimes quite handy.)
> You are trying to create a signal of your own. I don't think much of the python central tutorial you linked, it seems oriented to PySide and doesn't seem to match up with the PyQt5 doc, here:
>     http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html
> Follow the syntax under "Defining new signals with pyQtSignal". You are defining a class property, i.e. declared at the top level of a class definition, and what is not made explicit in that writeup, is that the class must derive from QObject (not python's object). Once you have defined the signal, e.g.
>     class myWidget( QWidget ):
>         databaseChanged = pyQtSignal()
> it is a property of the class ergo of every object of the class. In the __init__ probably you would do something like,
>     self.databaseChanged.connect( self.react_to_db )
> Or possibly in some OTHER object's __init__ it creates a myWidget and connects it:
>     new_widgy = myWidget(blah blah)
>     new_widgy.databaseChanged.connect( self.catch_new_widgy )
> When it is time to emit the signal, you just invoke its emit method,
>     if database_has_changed :
>         self.databaseChanged.emit()
> It looks as if you are trying to have your signal not just exist but pass a parameter? The syntax for that in pyQtSignal is a bit obscure and I'm not comfortable with it so maybe somebody else can write about that.
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150528/926fefb3/attachment.html>
-------------- next part --------------
PyQt mailing list    PyQt at riverbankcomputing.com

More information about the PyQt mailing list