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

J Barchan jnbarchan at gmail.com
Tue Nov 28 16:53:18 GMT 2017


On 28 November 2017 at 15:53, David Boddie <david at boddie.org.uk> wrote:

> On Tue Nov 28 09:01:30 GMT 2017, J Barchan wrote:
>
> > I now understand why PyQt has to use these "tuple" returns in places.  I
> > may not be a fan of the way Python has to do this, but at least I now
> know
> > what to look for in function declarations (non-const & references) which
> > will make me need to check the signature, instead of it appearing simply
> > "random" to me!
>
> Sorry, I misread what you wrote. The "const QString &filter" parameter
> isn't
> something that will be modified, but I suppose that the argument to
> the selectedFilter parameter could be modified - you do get the selected
> filter back as the second item in the tuple in Python.
>
> I should clarify that the "const QString &" pattern in signatures appears
> all over the place in Qt and is used for reasons I can't remember, but
> probably something to do with getting old C++ compilers to generate
> efficient code.
>
> I suppose that the hint that something could be modified is the use of a
> pointer for something you would expect to be passed by value or const
> reference. So, QString* instead of "const QString &".
>
> For what it's worth, in the old days of KDE 3 I encountered a method of a
> class that accepted a reference to a QImage that you were supposed to
> modify. If you assigned a new QImage to the parameter holding the original
> one, you didn't get the result you expected. This might have worked as
> expected in C++, but not in Python.
>
> https://api.kde.org/3.5-api/kdelibs-apidocs/kio/html/classTh
> umbCreator.html
>
> I don't know why the authors didn't just define a method that returned a
> QImage.
>
> Sorry for the confusion.
>
> David
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

​David, yes, I had already figured we were talking about the *non*-const
*selectedFilter​ parameter, as I wrote, rather than the const &filter one,
as the "reference" parameter PyQt is dealing with in the tuple return.  I
hadn't even noticed the Qt docs for this saying it could be returned,
hidden away on one line, as it didn't occur to me anyone would be
interested in getting that back from the call!  Not PyQt's fault.

Purely OOI, do we know whether the automated "Qt C++ to PyQt Python
converter" recognises this signature pattern (i.e. non-const * or &) and
automatically generates a tuple-return for it?  Somehow I doubt it (too
difficult, too reliant on C++ signature using const everywhere correctly),
so I'm thinking these tuple-returns are handled by the author manually?





-- 
Kindest,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20171128/23aa6940/attachment.html>


More information about the PyQt mailing list