funchelpers: Add a way to invoke a callable with a list of arguments
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 15 Oct 2018 22:39:31 +0000 (00:39 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 18 Nov 2018 10:06:43 +0000 (11:06 +0100)
commit0859ff9b7f8633925dde6482d57774f229a937a6
tree8fe0e427f2a166acd180299746e4202f8fa9498b
parent03ee70025a98912c163155955fe3cc3045f629b9
funchelpers: Add a way to invoke a callable with a list of arguments

In various places, we serialize function arguments as a QVariantList,
and later use QMetaMethod and friends to call a slot with that list.

In order to avoid this kind of runtime method lookup, we need a way
to directly invoke a given callable (e.g. a function pointer) with
a list of serialized arguments. We'll also want to use the type-based
conversion functionality of QVariant instead of using undocumented
methods and reinterpret_cast'ing raw memory, as is currently the case.

Provide a method invokeWithArgsList() that takes any callable and
a list of arguments serialized in a QVariantList, performs some
runtime sanity checks (argument count and types), and invokes the
callable with the arguments converted to the correct type, if
possible.

Also add a test case for this function.
src/common/funchelpers.h
tests/common/CMakeLists.txt
tests/common/funchelperstest.cpp [new file with mode: 0644]