On quarta-feira, 22 de março de 2017 03:26:21 PDT André Somers wrote:
> 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.

Ok, those are two good points (setting the initial value and ensuring each 
source property is bound to exactly one expression).

It could be a simple as:

template <typename Getter, typename Signal, 
                typename Receiver, typename Setter>
QMetaObject::Connection bind(QObject *sender, Getter getter, Signal signal,
                Receiver receiver, Setter setter)
{
        QMetaObject::Connection c = 
                connect(sender, signal, receiver, setter, 
Qt::ExclusiveConnetion);
        if (c)
                (receiver->*setter)( (sender->*getter)() );
        return c;
}

The only innovation here is Qt::ExclusiveConnection (which is different from 
Qt::UniqueConnection). The syntax needs a little work so that the setter can 
be a PMF or a lambda.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to