[PyQt] pyqt4topyqt5 a helper for the conversion PyQt4 to PyQt5

Baz Walter bazwal at ftml.net
Mon Jul 22 19:46:38 BST 2013


On 22/07/13 09:33, Vincent Vande Vyvre wrote:
> Hi,
>
> pyqt4topyqt5 is a script intended to help to the conversion PyQt4 to PyQt5.
>
> The main fixes are the changes QtGui > QtWidgets, QtWebKit >
> QtWebKitWidget, QtGui > QtPrintSupport, refactor signal-slot old style
> in new style, change the method in QFileDialog, QWheelEvent and QLayout.
>
> See the README for an exhaustive list of fixes
>
> So, this script was written for my own needs, feel free to send me yours
> observations.

Thanks for posting this. I had thought of doing something similar 
myself, but didn't find the time.

I haven't really tested your script much, but I found a couple of 
problems. The 'call_re' and 'slots_re' regexps only allow for 
double-quoted strings, so any single-quoted signals/slots will get the 
"Ambiguous syntax" message.

Also, your script needs to allow for overloads of signals with default 
arguments like "clicked(bool = 0)". This is a very common source of bugs 
when converting from old-style signals - there's even an example of it 
in your own README!:

     < self.connect(ui.right, SIGNAL("clicked()"), lambda angle=90: 
self.rotate(angle))
     > ui.right.clicked.connect(lambda angle=90: self.rotate(angle))

The old-style signal will pass no arguments to its handler, but the 
new-style signal will pass "False" by default (even if the button is not 
checkable). To avoid this issue, you must explicitly select the "no 
argument" overload with an empty tuple:

     ui.right.clicked[()].connect(lambda angle=90: self.rotate(angle))

I think there may be a few other signals that have similar issues 
(QAction.triggered is one that immediately springs to mind). The PyQt4 
class reference has details about the default overloads for new-style 
signals, e.g:

     http://pyqt.sourceforge.net/Docs/PyQt4/qabstractbutton.html#clicked
     http://pyqt.sourceforge.net/Docs/PyQt4/qaction.html#triggered

so you could try grepping that to find the others.

-- 
Regards
Baz Walter


More information about the PyQt mailing list