8 #include <Wt/WApplication.h> 10 #include <Wt/WContainerWidget.h> 12 #include <Wt/WPushButton.h> 29 this, std::placeholders::_1));
38 root()->
addWidget(cpp14::make_unique<WText>(
"<h2>Wt Javascript example</h2>" 39 "<p>Wt makes abstraction of Javascript, and therefore allows you" 40 " to develop web applications without any knowledge of Javascript," 41 " and which are not dependent on Javascript." 42 " However, Wt does allow you to add custom Javascript code:</p>" 44 " <li>To call custom JavaScript code from an event handler, " 45 "connect the Wt::EventSignal to a Wt::JSlot.</li>" 46 " <li>To call C++ code from custom JavaScript, use " 47 "Wt.emit() to emit a Wt::JSignal.</li>" 48 " <li>To call custom JavaScript code from C++, use " 49 "WApplication::doJavascript() or Wt::JSlot::exec().</li>" 51 "<p>This simple application shows how to interact between C++ and" 52 " JavaScript using the JSlot and JSignal classes.</p>"));
55 =
root()->
addWidget(cpp14::make_unique<WText>(
"Current amount: $" +
59 root()->
addWidget(cpp14::make_unique<WPushButton>(
"Change ..."));
60 amountButton->setMargin(10, Side::Left | Side::Right);
65 root()->
addWidget(cpp14::make_unique<WPushButton>(
"Pay now."));
66 confirmButton->setMargin(10, Side::Top | Side::Bottom);
71 confirmButton->clicked().connect(
confirmPay_->show);
80 confirmPay_->setMessage(
"Are you sure you want to pay $" + amount +
" ?");
91 root()->
addWidget(cpp14::make_unique<WText>(
"<br/>Just payed $" +
97 return cpp14::make_unique<JavascriptExample>(env);
100 int main(
int argc,
char **argv)
void confirmed()
The user has confirmed the payment.
WText * currentAmount_
WText for showing the current amount.
int main(int argc, char **argv)
std::unique_ptr< WApplication > createApplication(const WEnvironment &env)
std::unique_ptr< Popup > promptAmount_
Popup for changing the amount.
void setTitle(const WString &title)
bool setText(const WString &text)
void setAmount(std::string amount)
Set the amount to be payed.
std::unique_ptr< Popup > confirmPay_
Popup for paying.
WContainerWidget * root() const
JavascriptExample(const WEnvironment &env)
Create the example application.