[Development] Proposal: Deprecating platforms in Qt 5.6 that don't support lambda

Matthew Woehlke mw_triad at users.sourceforge.net
Thu Feb 19 21:41:42 CET 2015


On 2015-02-19 15:21, Marc Mutz wrote:
> On Thursday 19 February 2015 13:29:48 Daniel Teske wrote:
>> more than 400 lambdas in Creator's source
> 
> Sounds like lambdas are overused (as any new language feature is overused 
> before it's fully understood by the resp. language community).

Maybe, maybe not.

I'm not sure I've even *written* 400 lambdas yet :-), but I find myself
using them most often in QObject::connect. Basically, a lambda saves
writing a protected (or worse, *private*) slot by allowing the relevant
code to be written inline. These are rarely more than a few lines long,
and it's not unusual for them to be one-liners, e.g.:

  connect(d->UI.scrollBar, &QAbstractSlider::valueChanged,
          [d](int value){ d->scrollTo(value); });

The above is basically a private slot that's *actually private*. I've
also had cases of needing to connect a signal to a slot where the slot
needs to be called with additional (constant) arguments; these tend to
look like the above also.

Of course, the usual caveats of binding to a lambda apply, but in many
cases those aren't issues (e.g. my MainWindow class is not going to
disappear without taking its widgets with it, and said widgets aren't
likely to be emitting signals from other threads).

p.s. It would be cool if these restrictions could be relaxed by adding
an overload that takes a QObject that "owns" the slot.

>> and have several interfaces 
>> that take a std::function. 
> 
> What about boost::function?

Ugh, make Qt depend on boost? No, thanks...

-- 
Matthew




More information about the Development mailing list