The docs [1] clearly state what the method does. Moreover, the method is
const, so it can't mutate the object.

[1] https://doc.qt.io/qt-5/qdatetime.html#addDays

Cheers
Dmitriy

On Thu, Dec 13, 2018 at 3:04 PM NIkolai Marchenko <[email protected]>
wrote:

> This non obvious (from function name) behaviour actually caused infinite
> loop regression in our code just recently.
> The person used it inside a while loop thinking it will loop upwards and
> stop.
>
> On Thu, Dec 13, 2018 at 4:45 PM Edward Welbourne <[email protected]>
> wrote:
>
>> Fausto Papandrea (13 December 2018 12:48)
>> > Hi, I would like to understand the logic of the addDays function of
>> > QDateTime.
>> >
>> > I mean, why doesn't it modify the calling object, but returns a copy of
>> > a new object instead?
>>
>> At this point, it does what it does because it's done so for years
>> (since 5.0, at least) and changing it would break various compatibility
>> promises.  I guess the reason for it originally would be a general
>> preference for non-mutating methods; think of the add*() methods as
>> operator+() specialisations, rather than as operator+=().  If you need
>> to advance a QDateTime's day, you can always use
>>
>>   when->setDate(when.date().addDays(n));
>>
>> or simply
>>
>>   when = when.addDays(n);
>>
>> to achieve the mutating variant.
>>
>>         Eddy.
>> _______________________________________________
>> Development mailing list
>> [email protected]
>> https://lists.qt-project.org/listinfo/development
>>
> _______________________________________________
> Development mailing list
> [email protected]
> https://lists.qt-project.org/listinfo/development
>
_______________________________________________
Development mailing list
[email protected]
https://lists.qt-project.org/listinfo/development

Reply via email to