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

Florian Bruhin me at the-compiler.org
Wed May 27 17:42:02 BST 2015


* c c <coastalchaos at hotmail.co.uk> [2015-05-27 16:53:13 +0100]:
> Sorry for the formatting here it is again attached as a text file.

Yeah, Hotmail really likes to mangle plaintext mails...

> ##############     QT4       ###########################
> 
> class DatabaseProxy
> 
>     def onRegister(self):
> 
>         self.session =  self.new_event_session()
> 
>         # connect signals
> 
>         self.connect(Qt.Core.QCoreApplication.instance(),
>                QtCore.SIGNAL(b"databaseChanged(PyQt_PyObject)"),
>                self.on_database_updated_signal,
>                Qt.QueuedConnection)

I'm not used to the old signal/slot style - so this creates a new
databaseChanged signal on QApplication?

If you'd really want to do that, you'd need to subclass QApplication
and implement your signal there - but I'd prefer the way you outline
below.

> I've looked at examples such as http://www.pythoncentral.io/pysidepyqt-tutorial-creating-your-own-signals-and-slots/
> and I've come up with the below but I feel that something is missing......

Looks good to me. What do you think would be missing?

> ##############     QT5       ###########################
> 
> [...]
>     databaseChanged = pyqtSignal(object)
> [...]
>    @QtCore.pyqtslot(object)
>    def on_database_updated_signal(self, status)

If status is something like an int, you might want to use that instead
of 'object' here.

>            QtCore.QCoreApplication.instance().emit(
>                  self.attributeChanged)

As you say below, this should probably be:

    self.attributeChanged.emit()

> My question is, is this correct and what happens to the  QtCore.QCoreApplication.instance()

I don't understand the "what happens ..." question.

> Oh, I've also looked at the Qt documentation for QtAssistant and I cant see a change between Qt4 and Qt5 Qobject connect() method so I'm at a loss as to why we have the new signal/slot system in PyQt5 (I am aware that it was introduced in Qt4. I'm sure as I get to grips with pyQt / pyQt5 the reson will become apparent but I'm a long way off of that)

Probably to make things more pythonic, easier to write, and not based
on strings.

Note Qt5 actually also has a new signal/slot mechanism:

http://wiki.qt.io/New_Signal_Slot_Syntax

But that's mostly unrelated to the PyQt change.

Florian

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150527/a0a9000d/attachment.sig>


More information about the PyQt mailing list