[PyQt] Problems with new-style signal/slot syntax
phil at riverbankcomputing.com
Tue Apr 9 22:19:35 BST 2013
On Tue, 09 Apr 2013 21:06:44 +0100, Baz Walter <bazwal at ftml.net> wrote:
> When doing new-style connections, I normally use a Python type object as
> the selector (if necessary), and only very occasionally use a string.
> However, I was surprised to discover that this does not always work as
> expected. For example:
> from PyQt4 import QtGui, QtCore
> app = QtGui.QApplication()
> c = gui.QComboBox()
> works okay, but:
> m = QtGui.QMenu()
> gives this error:
> KeyError: 'there is no matching overloaded signal'
> After a bit of trial and error, it seems that signatures with "plain" or
> "const" arguments work okay, but the ones with "pointer" arguments
> don't. That is, unless the full C++ signature is used, in which case it
> always works:
> m.triggered['QAction *']
> <bound signal triggered of QMenu object at 0x2512b00>
> c.activated['const QString &']
> <bound signal activated of QComboBox object at 0x18308c0>
> (Is it intended that these latter two variants work? It doesn't seem to
> be documented anywhere).
Qt treats const QString& and plain QString as equivalent as far as signal
arguments are concerned. However QAction* is different to QAction. A
QObject derived instance will only ever be passed as a pointer, but that's
not true for other types. Therefore, for consistency, I think it would be
wrong to strip the "*". I agree the documentation could be clarified.
More information about the PyQt