[Development] invokeMethod() with function pointers

Olivier Goffart olivier at woboq.com
Fri Jan 20 11:01:25 CET 2017


On Freitag, 20. Januar 2017 09:59:55 CET Benjamin TERRIER wrote:
> 2017-01-20 3:01 GMT+01:00 Thiago Macieira <thiago.macieira at intel.com>:
> > we also catch the even more dubious code:
> >         char func[] = "deleteLater";
> >         QMetaObject::invokeMethod(&obj, func);

I think we should still support that.

> > 
> > The only case that would break would be for a constant null pointer
> > literal, which in my opinion is acceptable, since it should never happen
> > in real code.

I'd say breaking with 0 or nullptr is an acceptable source compatibility break 
since this makes no sens.


> As an alternative to adding "char *" overload, it seems that replacing
> "std::is_same<const char *,Func>"
> by "std::is_same<char *, Func>" in the "QtPrivate::QEnableIf" part of
> the template solves the issue
> for char * and const char *.

Maybe we need a smarter condition in the enable_if like is_callable or
!std::is_convertible<Func, const char *>

> Also I have checked QTimer and QTimer::singleShot(0, &obj, (char *)0);
> doesn't compile because
> the "wrong" overload is chosen. Removing the const in the std::is_same
> should also fix this.

this overload of QTimer::singleShot is meant to be used with the SLOT macro, 
so that's only a "const char*".  Nobody ever complained about that since Qt 
5.4 when it was added, so i think we could leave it like that.

But if you want to "fix" it there, there is also QMenu::addAction and 
QToolbar::addAction

-- 
Olivier

Woboq - Qt services and support - https://woboq.com - https://code.woboq.org



More information about the Development mailing list