[PyQt] Missing QIODevice::read overloads
phil at riverbankcomputing.com
Sun May 31 16:18:30 BST 2015
On 25/05/2015 9:40 pm, Florian Bruhin wrote:
> I noticed the following QIODevice overloads are missing in PyQt:
> qint64 QIODevice::read(char * data, qint64 maxSize)
> qint64 QIODevice::readLine(char * data, qint64 maxSize)
> only the following are available:
> QByteArray QIODevice::read(qint64 maxSize)
> QByteArray QIODevice::readLine(qint64 maxSize = 0)
> The issue with those is that it's impossible to check for errors:
> This function has no way of reporting errors; returning an empty
> QByteArray can mean either that no data was currently available
> for reading, or that an error occurred.
> The best workaround I found so far is to check if
> QIODevice::errorString is "Unknown error", but that's a hack...
> Maybe PyQt should provide the two other forms as well, when passing a
> mutable byte object (QByteArray/bytearray?) as first parameter?
I'm not sure what the best solution is. The reason the overloads are
missing is that, following the normal PyQt conventions, they would
return a str (Py2) or a bytes (Py3) but the signature would then be
indistinguishable from the overloads that return a QByteArray. Possible
1. Give the overloads a different Python name.
2. Change the existing methods to raise an exception (maybe initially a
warning) on error.
3. Pass a mutable object as an argument. If all Python versions are
still to be supported (something I don't think matters for PyQt5) then
it would have to by a QByteArray, otherwise (if only Python v2.6 and
later is to be supported) then a bytearray would do.
Given my previously stated desire to make better use of Python
deprecation warnings and to correct old, bad design decisions, then I'm
inclined towards option 2.
More information about the PyQt