[PyQt] PyQt documentation where PyQt function is not same as Qt C++ function

J Barchan jnbarchan at gmail.com
Mon Nov 27 16:59:54 GMT 2017


Thank you H-P & Florian.

First, my apologies Florian, I got confused, I mistook your name for Phil
Thompson's!  I have cc'ed this now to him too :)

Not only am I new to PyQt, but to Python too.  I had only just clicked that
the reason for these extra return values is that they are Reference/VAR
parameters in the C++ (which I hadn't particularly noticed).  Do you mean,
Python does not have these, you have to return these Tuples in the return
result as a way of achieving the same effect?  OMG, it's just horrible... :)

OK, at least I see the reason.  It's pretty hard to spot in the Qt
documentation, you have to check out the presence of &s (but not with const,
of which there are a lot) and read the small print in the docs to see
what's likely to be going on...

@Phil
If you are the developer, documenter, may I ask you then:
1. Could this be noted against the declaration in the .pyi file?
2. If not, should a PyQt overall document explain about this C++ -> Python
conversion behaviour?
3. OOI, why does PyQt5 QFileDialog.getOpen/SaveFileName() return that
second parameter?  Lemme guess: it's the QString *selectedFilter parameter,
isn't it?  The user can change that, and Qt returns it as well as the
filename, I guess, though I can't even see that in the Qt documentation...
Grrrrr!!


On 27 November 2017 at 16:40, Florian Bruhin <me at the-compiler.org> wrote:

> Hi,
>
> On Mon, Nov 27, 2017 at 03:53:28PM +0000, J Barchan wrote:
> > [Also cc'ed to "Florian Bruhin", as I believe you have indicated that you
> > are "The Man"!]
>
> I'm just a "normal" user of PyQt ;-)
>
> Phil Thompson is "the man", but as mentioned on [1], this mailing list is
> the
> right place to ask :)
>
> [1] https://www.riverbankcomputing.com/support/help
>
> > 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.
>
> Probably the fixed input and new position.
>
> > If you *really* need to return different information from the C++
> function
> > (why?  to do with overloading not working the same??)
>
> Because C++ can write a new value back to input/pos (because they're
> passed as
> reference), but Python can't.
>
> Florian
>
> --
> https://www.qutebrowser.org  | me at the-compiler.org (Mail/XMPP)
>    GPG: 916E B0C8 FD55 A072  | https://the-compiler.org/pubkey.asc
>          I love long mails!  | https://email.is-not-s.ms/
>



-- 
Kindest,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20171127/35ebc26f/attachment-0001.html>


More information about the PyQt mailing list