[Development] std::chrono getters in our API

Matthew Woehlke mwoehlke.floss at gmail.com
Fri Jun 17 21:54:28 CEST 2016


On 2016-06-10 19:27, Thiago Macieira wrote:
> On sexta-feira, 10 de junho de 2016 16:12:10 PDT Matthew Woehlke wrote:
>> On 2016-06-10 13:53, Thiago Macieira wrote:
>>> I've added a set of std::chrono API to QTimer[1] and QDeadlineTimer[2] and
>>> we're hitting a snag on what to name the getters. The setters are fine
>>> because> 
>>> they're just overloads:
>>> 	timer.setInterval(3);		// Qt; milliseconds
>>> 	timer.setInterval(3ms);
>>> 	deadline.setRemainingTime(3600000); 	// milliseconds
>>> 	deadline.setRemainingTime(1h);
>>> 	deadline.setDeadline(QDeadlineTimer::current().deadline() + 3600000);
>>> 	deadline.setDeadline(std::chrono::steady_clock::now() + 1h);
>>>
>>> The problem are the getters: what do we call them?
>>
>> Qt6-only option... return a QTimeInterval or some such with (implicit)
>> conversion operators.
> 
> QTimeInterval helps for std::chrono::duration, but not for the other use in 
> QDeadlineTimer: deadline() returns the equivalent of a 
> std::chrono::time_point.
> 
> QDeadlineTimer *is* the equivalent of a std::chrono::time_point.
> 
>> I expect there are issues with that, but feels worth mentioning at least
>> for the sake of discussion.
> 
> So, you're suggesting not doing anything now, leave std::chrono support out in 
> Qt 5, and do it only for Qt 6?

I'm suggesting that a possible solution to the problem is to return a
single complex type¹ that can be converted - perhaps implicitly - into
the desired simple types (e.g. int milliseconds, std::chrono types). I
wouldn't go so far as to claim that as the *best* solution :-).

(¹ Or, the appropriate of several such types, as needed.)

-- 
Matthew




More information about the Development mailing list