Wt examples 4.7.2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
HelloApplication Class Reference
Inheritance diagram for HelloApplication:
Inheritance graph
[legend]

Public Member Functions

 HelloApplication (const Wt::WEnvironment &env)
 

Private Member Functions

void greet ()
 

Private Attributes

Wt::WLineEdit * nameEdit_
 
Wt::WText * greeting_
 

Detailed Description

Definition at line 18 of file hello.C.

Constructor & Destructor Documentation

◆ HelloApplication()

HelloApplication::HelloApplication ( const Wt::WEnvironment &  env)

Definition at line 36 of file hello.C.

37 : WApplication(env)
38{
39 setTitle("Hello world"); // application title
40
41 root()->addWidget(std::make_unique<Wt::WText>("Your name, please ? ")); // show some text
42
43 nameEdit_ = root()->addWidget(std::make_unique<Wt::WLineEdit>()); // allow text input
44 nameEdit_->setFocus(); // give focus
45
46 auto button = root()->addWidget(std::make_unique<Wt::WPushButton>("Greet me."));
47 // create a button
48 button->setMargin(5, Wt::Side::Left); // add 5 pixels margin
49
50 root()->addWidget(std::make_unique<Wt::WBreak>()); // insert a line break
51 greeting_ = root()->addWidget(std::make_unique<Wt::WText>()); // empty text
52
53 /*
54 * Connect signals with slots
55 *
56 * - simple Wt-way: specify object and method
57 */
58 button->clicked().connect(this, &HelloApplication::greet);
59
60 /*
61 * - using an arbitrary function object, e.g. useful to bind
62 * values with std::bind() to the resulting method call
63 */
64 nameEdit_->enterPressed().connect(std::bind(&HelloApplication::greet, this));
65
66 /*
67 * - using a lambda:
68 */
69 button->clicked().connect([=]() {
70 std::cerr << "Hello there, " << nameEdit_->text() << std::endl;
71 });
72}
Wt::WText * greeting_
Definition: hello.C:25
void greet()
Definition: hello.C:74
Wt::WLineEdit * nameEdit_
Definition: hello.C:24

Member Function Documentation

◆ greet()

void HelloApplication::greet ( )
private

Definition at line 74 of file hello.C.

75{
76 /*
77 * Update the text, using text input into the nameEdit_ field.
78 */
79 greeting_->setText("Hello there, " + nameEdit_->text());
80}

Member Data Documentation

◆ greeting_

Wt::WText* HelloApplication::greeting_
private

Definition at line 25 of file hello.C.

◆ nameEdit_

Wt::WLineEdit* HelloApplication::nameEdit_
private

Definition at line 24 of file hello.C.


The documentation for this class was generated from the following file:

Generated on Fri May 13 2022 for the C++ Web Toolkit (Wt) by doxygen 1.9.4