Category Archives: C++

Wt Web Toolkit: Get URL parameter string values

If you want to access an url parameter string in Witty C++ HTML Web Toolkit there is an easy way to do so. Imagine you want to get the content of the parameter “param” in a URL like http://www.myurl.com/?param=test. To do so you can use the following code in your Wt Application class:


#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <string>
#include <iostream>

using namespace Wt;

class myApplication: public WApplication
{
public:
  myApplication(const WEnvironment& env)
    : WApplication(env)
  {
    setTitle("This is an application");

    addMetaHeader ("description","a description");

    const std::string* param =    this->environment().getParameter("param"); 

    if (param!=0)
    {
        std::cout << (*param) << std::endl;
    } 
 

 }

}


Also have a look of the handling of internal paths in Wt Web Toolkit:

http://www.webtoolkit.eu/wt/doc/tutorial/wt.html

Advertisements

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!