Wt C++ Web Toolkit: How to send parameters to a slot using the boost::bind routine

Since I did not find any documentation for this in the web: If you are using Wt C++ Web toolkit and ever wondered, how to send parameters to a SLOT() there is a simple solution using the boost::bind routine.

Imagine you have an button, and an event that requires one parameter then you can setup the whole scenario like this:

void MyClass::test(std::string parameter)
{
  cout << parameter << endl;
}

WPushButton *button = new WPushButton("Test", this);

button->clicked().connect(boost::bind(&MyClass::test, this, "Hello World!"));

The step which is often forgotten is to put the instance of the class right after the function pointer. (In this case “this”)

Thats it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: