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

c c coastalchaos at hotmail.co.uk
Thu May 28 12:58:58 BST 2015


Sorry hit reply instead of reply all.

> On 27 May 2015, at 18:39, c c <coastalchaos at hotmail.co.uk> wrote:
> 
> Florian,
>  
> Thanks for taking the time to answer. I looked at the post on the mailing list and I was compacted but it was ok when it hit my inbox.
>  
>  
> My confusion regarding the "what happens to..." is that the  QCoreApplication.instance() is no longer in the new signal/slot connection definition.
>  
> I assume the old way meant that the signal was created for the instance of QCoreApplication but the new way of doing it is nto bringing it into play. Maybe it was the wrong thing to do originally???
>  
>  
> I'm inheriting this code/project so I thought I might as well bring it up to date regarding Qt5/PyQt5 but staying with python 2.7 due to libraries that are used in the project that haven't been ported (although I guess I should check the latest status of those one by one) but I wanted to change as little as possible while I try and get to grips with it. I felt if I progressed with PyQt4/Qt4 I might end up having to port when I've got a bigger application which would be worse.
>  
>  
> I've changed the declaration to the new way and the code runs past that point which is good but I've got every single signal/slot to rewrite which is 318. I'm hoping when I've finished that lot I won't run into too may problems due to the transition from 4 to 5 but I see that other commands are falling over :(. 
>  
>  
> Has anyone else gone through the pain of PyQt4/Qt4  to PyQt5/Qt5 migration and is there any general advice?
>  
>  
>  
> Rob
>  
>  
>  
>  
> 
>  
> Date: Wed, 27 May 2015 18:42:02 +0200
> From: me at the-compiler.org
> To: pyqt at riverbankcomputing.com
> Subject: Re: [PyQt] converting old signal/slot to new signal/slot
> 
> * 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(QtCore.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/
> 
> _______________________________________________ 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/ae63b68f/attachment.html>


More information about the PyQt mailing list