[Interest] Qt 5 connect to static function: Suggestion for new overload.
Björn Piltz
bjornpiltz at gmail.com
Fri May 3 11:50:14 CEST 2013
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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130503/88fd2c84/attachment.html>
More information about the Interest
mailing list