[Qt-interest] Advices on safer SIGNAL macro
Johannes Schaub
schaub.johannes at googlemail.com
Wed Oct 19 21:47:18 CEST 2011
I've written myself a custom SIGNAL macro that at compile time checks that
all parameter types I gave in the signature passed to SIGNAL are known at
the point of use of SIGNAL:
namespace static_signal_detail {
template<typename>
struct take { };
}
#define STATIC_SIGNAL(SIG) (static_signal_detail::take<void(void SIG)>(), \
SIGNAL(SIG))
For example it would throw a *compile time* error if in the following, you
wrote "Ptr" instead of "common::Ptr" (as happened for me today). Using the
original SIGNAL macro, it would do nothing. Alternatively one could check
the return value of "connect" and throw / abort, but that would be a runtime
error, only noticed when the "connect" is actually executed:
connect(pages, SIGNAL(changed(Ptr)), SLOT(update(Ptr)));
Is there any problem with my version of SIGNAL? I'm searching for advices on
how to make it better or on how it sucks so bad that I should just burry it
and move on.
More information about the Qt-interest-old
mailing list