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

David Boddie david at boddie.org.uk
Tue Nov 28 15:53:39 GMT 2017


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/classThumbCreator.html

I don't know why the authors didn't just define a method that returned a
QImage.

Sorry for the confusion.

David


More information about the PyQt mailing list