[PyQt] PyQt documentation where PyQt function is not same as Qt C++ function
Hans-Peter Jansen
hpj at urpla.net
Mon Nov 27 16:38:43 GMT 2017
On Montag, 27. November 2017 15:53:28 J Barchan wrote:
>
> Dear PyQt developers/maintainers/documenters,
>
> [Also cc'ed to "Florian Bruhin", as I believe you have indicated that you
> are "The Man"!]
>
> I'm getting a little peeved by the problems which arise when you seem to
> have chosen to make a PyQt function differ somewhat (in return result, so
> far) from the corresponding Qt C++ function, but no documentation to
> explain can be found. (This may apply only to PyQt5, not PyQt4, I don't
> know.)
>
> I was just trying to write an override in my own class for
> QRegularExpression.validate(). The Qt documentation (
> http://doc.qt.io/qt-5/qregularexpressionvalidator.html#validate) shows:
>
> QValidator::State <http://doc.qt.io/qt-5/qvalidator.html#State-enum>
> QRegularExpressionValidator::validate(QString
> <http://doc.qt.io/qt-5/qstring.html> &*input*, int &*pos*) const
> So I expect it to return a QValidator.State. However, QtGui.pyi shows:
>
> def validate(self, input: str, pos: int) ->
> typing.Tuple[QValidator.State, str, int]: ...
>
> So this is a tuple, with an extra str & int returned.
>
> Apart from the fact that it's a tuple instead of a plain enum returned, I
> have *no idea* what the extra str & int might be, what to do with them, etc.
This is due to the poor C++ way of dealing with multiple return values, while avoiding to
define yet another typedef... You supply references to parameter values by the ampersand
(&). Expect these values modified in the method call.
In Python, that concept translates to a tuple return value rather naturally. PyQt follows the
pattern "return value", "1st reference value", "2nd..." for the returned tuple order.
Cheers,
Pete
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20171127/671e0fdc/attachment.html>
More information about the PyQt
mailing list