I'm trying to create a macro that will install and remove a Qt event filter constructed from a lambda. In this case, this
is known to be a QObject
, and thus has a member destroyed
. filter
is just some QObject
-derived event filter. However I have a problem with the line:
connect(this, &decltype(this)::destroyed, [filter]()
{
qApp->removeEventFilter(filter);
filter->deleteLater();
});
which gives the (MSVC2013) error:
left of '::' must be a class, struct or union
Am I just getting the syntax wrong, or can I not do this?
Per @molbdnilo's comment, I wasn't accounting for the fact that this
is a pointer. Using a type-trait to remove the pointer made it work:
connect(this, &std::remove_pointer<decltype(this)>::type::destroyed, [filter]()
{
qApp->removeEventFilter(filter);
filter->deleteLater();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.