[Development] QTextStream::readLine(0) is an ambiguous overload in 5.5

Thiago Macieira thiago.macieira at intel.com
Wed May 13 02:44:40 CEST 2015

On Wednesday 13 May 2015 02:34:28 Jan Kundrát wrote:
> Hi,
> this commit [1] added a new overload to QTextStream::readLine. As a result
> of that, calling stream.readLine(0) is now ambiguous:
>     QString readLine(qint64 maxlen = 0);
>     bool readLine(QString *line, qint64 maxlen = 0);
> While I can easily fix this in the caller (Konsole in this case), I'm
> wodnering whether this effect was understood at the time the change was
> merged. IMHO it's a bit more user-friendly to preserve source compatibility
> by removing the default value in the newly added overload.
> Should I send such a patch?

Why write readLine(0) when it's the same as readLine() ? readLine(0) seems to 
me that it's asking for a line of at most zero bytes -- we should have had 
this argument default to -1 to indicate maximum length, not 0.

Removing the default argument for the new overload will make it worse, by 
making people have to write the zero when they mean unlimited. I don't like 
that. The two options I will consider are:

a) do nothing, accept and document the source incompatibility
b) modify differently so that the new API isn't ambiguous but doesn't require 
people to write 0 either.
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Development mailing list