[Interest] Convert to QMetaMethod from QObject + const char *
Volker Hilsheimer
volker.hilsheimer at qt.io
Wed Aug 17 11:23:37 CEST 2022
> On 16 Aug 2022, at 22:39, Scott Bloom <scott at towel42.com> wrote:
>
> I have a function that takes in a QObject and const char * signal/slot
>
> void func( …, QObject * target, const char * member )
> {
> …. logic
> QObject::connect( ….., target, member )
> … more logic
> {
>
>
> So I can call it via
>
> ….
> func( …., m_target, SLOT( XXXX )
> …
>
> it works fine
>
> I would like to modify the function so it can also take
>
> func( …., m_target, &TargetClass::XXXX
>
>
> however, I cant for the life of me figure out to convert, if its even possible
>
> Id prefer not to have to copy all the logic in func
>
> Is this possible?
>
> Yes, I know I can use std::enable_if, but that just copies the function logic
>
> Thanks
> Scott
Check QHostInfo::lookupHost for a Qt API that does that. It relies on private Qt APIs though.
There might be C++17-ways to simplify some of that using `if constexpr`, but the basics will probably be the same.
Volker
More information about the Interest
mailing list