Hey,

2012/11/27 John Robson <john.rob...@usp.br>:
> WPushButton* pb = new WPushButton(tr("update"));
> pb->clicked().connect(this, &Users::listUpdate);
>
> If I want use Parameters inside listUpdate function:
>
> void Assets::listUpdate(int type, string path) { ... }
>
> I can't do:
> pb->clicked().connect(this, &Users::listUpdate(1, "home"));
>
>
> What I can do?  Use a WSignalMapper ? Or is there another better way?

This is the classic Wt FAQ.

The easiest way is to use learn how to use boost::bind() (or c++11
std::bind()). It may be intimidating at first, but once you get it,
it's a simple and versatile tool.

In your case, you would write:

pb->clicked().connect(boost::bind(&User::listUpdate, this, 1, "home"));

Roughly speaking boost::bind(F, a1, a2, a3) will call function F(a1, a2, a3).
Buf if F is a method then the first argument a1 is actually the object
pointer: a1->F(a2, a3).

But boost::bind() is actually a function whose result is a new
function, in a more general way. The example above creates a function
that accepts no parameters. You can still create a function that
accepts parameters using placeholders _1, _2, ... Thus: boost::bind(F,
a1, _1) will call create a function with one parameter _1 which when
invoked, calls function F(a1, _1).

Regards,
koen

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to