[Qt-interest] Question SLOT Macro & messing with the QObject::connect method

kent williams nkwmailinglists at gmail.com
Thu Feb 4 18:54:47 CET 2010


I don't think you understand what Slot does.

#define SLOT(a) "1"#a

# is the preprocessor 'stringify' operation.  It takes the argument
and turns it into a string literal. For example
SLOT(kickme())

is turned by the C Preprocessor into

"1" "kickme()"

and since adjacent string literals are merged, it will become

"1kickme()"

So you can _ONLY_ use the SLOT macro at compile time.

At runtime, say, if you want to stick a bunch of boilerplate Qt code
into a convenience function, you just can't use SLOT(), because
there's no way to go from a passed const char * parameter back to a
string literal to use for a SLOT parameter.  You  can fake it -- which
is what I do -- create a string at runtime with a literal '1'
prepended.

The problem, as I see it, is that with respect to proper C++ the
SIGNAL/SLOT/METHOD business is stuck in the compile-time realm, even
the the whole POINT of Qt's Signals and Slots paradigm is that the
connections between signals and slots happen at runtime!


On Thu, Feb 4, 2010 at 11:17 AM, Ian Thomson <Ian.Thomson at iongeo.com> wrote:
> Hi,
>
> kent williams wrote:
>>
>> So my question is this: is there a non-evil way to get around SLOT()
>> requiring a string literal instead of a char * variable?
>
> Isn't the const char* you're talking about a literal somewhere else in your
> program? Call SLOT() on it there.
>
>
> Cheers,
> Ian.
>



More information about the Qt-interest-old mailing list