[Development] Property bindings in Qt 6
Jason H
jhihn at gmx.com
Tue Oct 1 16:12:58 CEST 2019
> I’m all for a more declarative coding style also in C++.
> I’m wondering if we are re-inventing part of Reactive Programing a la ReactiveX with QProperty, though?
>
> The above looks similar to (sodium-cxx):
>
> cell_sink<QString> surname("John");
> cell_sink<QString> lastname("Smith”);
> cell<QString> fullname = surname.lift(
> lastname, [](QString s, QString l) { return s + " " + l; });
>
> qDebug() << fullname.sample();
> surname.send("Emma");
> qDebug() << fullname.sample();
>
> or (RxJS):
>
> var surname = new BehaviorSubject("John");
> var lastname = new BehaviorSubject("Smith");
> var fullname = new BehaviorSubject();
> r.combineLatest(surname, lastname).pipe(map(([s, l]) => { return s + " " + l; })).subscribe(fullname);
>
> console.log(fullname.getValue());
> surname.next("Emma”);
> console.log(fullname.getValue());
>
> What is the relation of QProperty to Reactive Programing, in which ways can we orient QProperty on what is done there, or learn from insights in that field?
> Using "fullname.listen([](QString s) { qDebug() << s; });" (or "fullname.subscribe(s => console.log(s));”) instead of the explicit logging in the example above
> will print “John Smith”, whereas using change event listeners always requires special handling of the initial value.
I would (naively) think that this would be done by creating a default-constructed value, then setting it?
So I've used knockout and observables, and at the same time used Qt, and I always preferred QML over the bindings with that framework.
I'm wondering (out loud) if we aren't kinda talking about a opposite of QGadget for our classes - one where it can just emit a changed() event for applicable setters. I'm not sure how much of moc would have to be brought in - obviously we wouldn't want it on every class...?
More information about the Development
mailing list