[Development] invokeMethod() with function pointers

Benjamin TERRIER b.terrier at gmail.com
Fri Jan 20 09:59:55 CET 2017

2017-01-20 3:01 GMT+01:00 Thiago Macieira <thiago.macieira at intel.com>:
> Because it's a template, so the template when Func = char* matches better than
> the overload with const char*. I assume that using nullptr without casting
> also breaks, correct?


> From what you explained, this will not affect the case when the pointer is a
> const char *, so neither
>         const char *func = "deleteLater";
>         QMetaObject::invokeMethod(&obj, func);
> nor
>         const char *func = nullptr;
>         QMetaObject::invokeMethod(&obj, func);
> will stop compiling. So if you add an overload taking a non-const char* (and
> its unit test), we also catch the even more dubious code:
>         char func[] = "deleteLater";
>         QMetaObject::invokeMethod(&obj, func);
> 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.

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 *.

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.

More information about the Development mailing list