On Fri, Sep 12, 2008 at 10:42:59AM +0200, Jose M. Sanchez wrote:
> 
> Hi,
> 
> I have different widgets created in a generic way with slots connected 
> to the same method. How can I know which widget triggered the event?
> 
> void Test::createWidgets()
> {
>     WText *text1 = new WText(...);
>     WText *text2 = new WText(...);
>     WText *text3 = new WText(...);
> 
>     text1->clicked.connect(SLOT(this, Test::onClick));
>     text2->clicked.connect(SLOT(this, Test::onClick));
>     text3->clicked.connect(SLOT(this, Test::onClick));
> }
> 
> 
> 
> void Test::onClick()
> {
>     // how do I know here which WText was clicked?
> 
>     WObject *sender = clicked.sender();
>     // sender() is the instance of the Test class, not the WText widget
> }

You want to use WSignalMapper! The example given in the documentation
for that class if I remember was quite confusing. So here is what you
want instead (completly from heart I am probably fully wrong here)

void Test::createWidgets()
{
        WSignalMapper<WText*> MyMap* = new WSignalMapper<WText*>(this);
        MyMap->mapped.connect(SLOT(this,Test::onClick));
        MyMap->mapConnect(text1->clicked,text1);
        MyMap->mapConnect(text2->clicked,text2);
        MyMap->mapConnect(text3->clicked,text3);
}

void Test::onClick(WText* source)
{
        // source is where it is coming from
}

cu bart

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to