[Interest] Requesting QObject::bind() method

André Somers andre at familiesomers.nl
Wed Mar 22 11:26:21 CET 2017



Op 22/03/2017 om 07:49 schreef Thiago Macieira:
> 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.
>
That's not quite true. First of all, you are not referencing the getter
in the example above. Then, a ::bind would also initialize the receivers
value to the current value. Qt::connect does not do that. Also, a ::bind
suggests that the connection is exclusive at the receiving end and
setting a new bind will break the old one; a connection explicitly is not.

André




More information about the Interest mailing list