[Interest] Requesting QObject::bind() method
Thiago Macieira
thiago.macieira at intel.com
Wed Mar 22 07:49:17 CET 2017
Em terça-feira, 21 de março de 2017, às 22:58:38 PDT, Thiago Macieira
escreveu:
> Em terça-feira, 21 de março de 2017, às 19:38:19 PDT, Prashanth Udupa
>
> escreveu:
> > QSlider *slider = ...
> > QLabel *label = ....
> > QObject::bind(slider, "value", label, "text”);
>
> This is a bad example because "text" is a string and would require a
> conversion. But let's say we're connecting a slider to a QProgressBar. You
> can just write:
>
> QObject::connect(slider, &QSlider:valueChanged,
> &progressBar, &QProgressBar::setValue);
And your other example:
> QSlider *slider = ....
> QLabel *label = ....
> QObject::bind(slider, "value", label, "text", [](const QVariant &v) { return
> v.toInt()*2; });
Would be:
QObject::connect(slider, &QSlider::valueChanged, &label, [label](int value) {
label->setText(QString::number(value * 2));
});
But let me put it this way: will not accept new text-based API for signal,
slots and properties in QObject. You can do that externally, as you've done
it, but I won't take it in QtCore.
So we need the compile-time checking. What can we use to identify the property
changing? A read-only property that changes has two C++ identifiers: the getter
and the notify signal. And what can we use to identify the receiving property?
The getter and the setter.
So this new functionality would be:
QObject::bind(sender, &Sender::signalName, receiver, &Receiver::setter);
This is exactly connect() we already have.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Interest
mailing list