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

Andre Somers andre at familiesomers.nl
Sun May 17 14:30:16 CEST 2015


On 13-5-2015 2:44, Thiago Macieira wrote:
> 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.
In the spirit of option b), would it be an option to have the method 
take a QString& instead of a QString*? That would resolve the ambiguity. 
It also makes it clear that it makes little sense to call the method 
without an actual QString to store the results in.

André




More information about the Development mailing list