-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloApplication.cpp
More file actions
52 lines (44 loc) · 1.75 KB
/
Copy pathHelloApplication.cpp
File metadata and controls
52 lines (44 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "HelloApplication.hpp"
/*
* The env argument contains information about the new session, and
* the initial request. It must be passed to the WApplication
* constructor so it is typically also an argument for your custom
* application constructor.
*/
HelloApplication::HelloApplication(const Wt::WEnvironment& env)
: WApplication(env)
{
setTitle("Hello world"); // application title
root()->addWidget(Wt::cpp14::make_unique<Wt::WText>("Your name, please ? ")); // show some text
nameEdit_ = root()->addWidget(Wt::cpp14::make_unique<Wt::WLineEdit>()); // allow text input
nameEdit_->setFocus(); // give focus
auto button = root()->addWidget(Wt::cpp14::make_unique<Wt::WPushButton>("Greet me."));
// create a button
button->setMargin(5, Wt::Side::Left); // add 5 pixels margin
root()->addWidget(Wt::cpp14::make_unique<Wt::WBreak>()); // insert a line break
greeting_ = root()->addWidget(Wt::cpp14::make_unique<Wt::WText>()); // empty text
/*
* Connect signals with slots
*
* - simple Wt-way: specify object and method
*/
button->clicked().connect(this, &HelloApplication::greet);
/*
* - using an arbitrary function object, e.g. useful to bind
* values with std::bind() to the resulting method call
*/
nameEdit_->enterPressed().connect(std::bind(&HelloApplication::greet, this));
/*
* - using a lambda:
*/
button->clicked().connect([=]() {
std::cerr << "Hello there, " << nameEdit_->text() << std::endl;
});
}
void HelloApplication::greet()
{
/*
* Update the text, using text input into the nameEdit_ field.
*/
greeting_->setText("Hello there, " + nameEdit_->text());
}