Say I want to connect a signal like editingFinished() to a slot like
setWindowModified(bool) with a default argument for the bool. With Qt 5
there are two one line solutions to do this:


    QObject::connect(sender, &QLineEdit::editingFinished,
std::bind(&QWidget::setWindowModified, receiver, true));

    QObject::connect(sender, &QLineEdit::editingFinished,
[receiver](){receiver->setWindowModified(true);});


The problem with this approach is that the Qt framework is completely
unaware of the receiver object and if it is deleted your application
will crash the next time editingFinished() is emitted.


Would it be possible to add an overload of QObject::connect() like this:

static QMetaObject::Connection connect(const QObject *sender,
PointerToMemberFunction signal, const QObject *receiver, Functor
functor);

in addition to

static QMetaObject::Connection connect(const QObject *sender,
PointerToMemberFunction signal, Functor functor);


The only difference being that the connection is severed when sender or
receiver is deleted.


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

Reply via email to