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

Jefferson Bandeira jbsilva at ufrj.br
Thu Feb 4 20:19:54 CET 2010


I really can't see what exactly you're trying to do with that piece of code,
are you trying to introduce Custom Slots at runtime? 'Cause i think it's not
supported at all, if it's not this, could you clarify a bit what exactly are
you trying to do?

2010/2/4 kent williams <nkwmailinglists at gmail.com>

> 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.
> >
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>



-- 
Jefferson Bandeira
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100204/7fa06030/attachment.html 


More information about the Qt-interest-old mailing list