1
|
|
2
|
|
3
|
// > g++ -o main main.cc -lcrypt -lwthttp -lwt -lboost_signals-mt -lboost_system-mt
|
4
|
// > ./main --docroot . --http-address 127.0.0.1 --http-port 9090
|
5
|
|
6
|
|
7
|
|
8
|
#include <sstream>
|
9
|
|
10
|
#include <Wt/WApplication>
|
11
|
#include <Wt/WContainerWidget>
|
12
|
#include <Wt/WPushButton>
|
13
|
#include <Wt/WText>
|
14
|
#include <Wt/WBreak>
|
15
|
|
16
|
using namespace std;
|
17
|
using namespace Wt;
|
18
|
|
19
|
class MyApp : public WApplication
|
20
|
{
|
21
|
public:
|
22
|
|
23
|
MyApp(const WEnvironment& env)
|
24
|
: WApplication(env)
|
25
|
{
|
26
|
WPushButton* button1 = new WPushButton( "Button 1", root() );
|
27
|
button1->clicked().connect( this, &MyApp::changePath1 );
|
28
|
|
29
|
WPushButton* button2 = new WPushButton( "Button 2", root() );
|
30
|
button2->clicked().connect( this, &MyApp::changePath2 );
|
31
|
|
32
|
new WBreak(root());
|
33
|
state_text = new WText("no button pushed yet", root());
|
34
|
|
35
|
internalPathChanged().connect( this, &MyApp::handlePathChange );
|
36
|
}
|
37
|
|
38
|
WText *state_text;
|
39
|
|
40
|
void changePath1() {
|
41
|
std::cerr << "Button1 clicked" << std::endl;
|
42
|
setInternalPath( "/page1", false );
|
43
|
state_text->setText("greatest button pushed: button 1");
|
44
|
}
|
45
|
|
46
|
void changePath2() {
|
47
|
std::cerr << "Button2 clicked" << std::endl;
|
48
|
setInternalPath( "/page2", false );
|
49
|
state_text->setText("leastest button pushed: button 2");
|
50
|
}
|
51
|
|
52
|
void handlePathChange( std::string path )
|
53
|
{
|
54
|
std::cout << "handlePathChange " << path << std::endl;
|
55
|
stringstream ss;
|
56
|
ss << "silly user, you manually navigated to: " << path;
|
57
|
ss << " which is the same as: " << internalPath();
|
58
|
state_text->setText(ss.str());
|
59
|
}
|
60
|
};
|
61
|
|
62
|
WApplication *createMyApplication(const WEnvironment& env)
|
63
|
{
|
64
|
return new MyApp(env);
|
65
|
}
|
66
|
|
67
|
int main(int argc, char **argv)
|
68
|
{
|
69
|
return WRun(argc, argv, &createMyApplication);
|
70
|
}
|