2010/6/24 Diego Cantor-Rivera <[email protected]>:
> Hello,
>
> I have a bunch of WPushButtons and I want to call different Javascript
> functions whenever the user clicks them. I was reading about the
> WSignalMapper and I have a couple of questions.
>
> 1. If you pass the source object as the second argument of the mapConnect
> method how do you determine in your slot which object is that? I mean, can
> you do something like:
>
>  if (source == btnOption1)
>
> ... inside the slot?
>

yes. Seel also WObject::sender()

>
> 2. I am getting a bunch of template errors when I tried to pass an enum
> value instead of the source object as the second argument of the mapConnect
> method. What would be (if any) the correct way to do that?
>
> Example:
>
> enum {OPTION1, OPTION2}
>
> and I want to do something like this:
>
> mymap->mapConnect(btnOption1->clicked(), OPTION1}
> mymap->mapConnect(btnOption2->clicked(), OPTION2}
>

Which compiler? gcc compiles this fine:

enum Foo {FOO_ONE, FOO_TWO};

...

WSignalMapper<Foo> *sm = new WSignalMapper<Foo>(root());
sm->mapConnect(_editor->clicked(), FOO_ONE);

> 3. In a different scenario, I want to connect my buttons with javascript
> functions on the page. If I am correct, according to the docs you use a
> JSlot object to do that. Now, you need to use the setJavaScrip method which
> receives a string contains a javascript function with the signature
> "function(sender,event)..."
>
> If my functions are already in the webpage and changing their signature is a
> pain in the ass, can I write a string like ...
>
>
> #define WT_JS(...) #__VA_ARGS__
> ...
> "function (sender,event){ " + WT_JS($(function(){myfunction();});) + "}"
>
> Is there a shorter way to do this?
>

I think the proper syntax would be
setJavaScript("function(s,e){myfunction();}");. No need to further
complicate such simple functions!

Best regards,
Wim.

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to