|
#include <Wt/WApplication>
|
|
#include <Wt/WBreak>
|
|
#include <Wt/WContainerWidget>
|
|
#include <Wt/WLineEdit>
|
|
#include <Wt/WPushButton>
|
|
#include <Wt/WText>
|
|
|
|
using namespace Wt;
|
|
|
|
class HelloApp : public WApplication {
|
|
public:
|
|
HelloApp(const WEnvironment& env);
|
|
|
|
private:
|
|
WLineEdit *nameEdit_;
|
|
WText *greeting_;
|
|
|
|
void greet();
|
|
};
|
|
|
|
HelloApp::HelloApp(const WEnvironment& env) : WApplication(env) {
|
|
setTitle("Hello World");
|
|
|
|
root()->addWidget(new WText("Your name, please? "));
|
|
// show text
|
|
nameEdit_ = new WLineEdit(root());
|
|
nameEdit_->setFocus();
|
|
|
|
WPushButton *b = new WPushButton("Greet me.", root());
|
|
b->setMargin(5, WWidget::Left);
|
|
|
|
root()->addWidget(new WBreak()); // empty link break
|
|
|
|
greeting_ = new WText(root()); // empty text
|
|
|
|
// Connect signals with slots
|
|
|
|
b->clicked.connect(SLOT(this, HelloApp::greet));
|
|
nameEdit_->enterPressed.connect(SLOT(this, HelloApp::greet));
|
|
}
|
|
|
|
void HelloApp::greet() {
|
|
// Update the text using input in the nameEdit_
|
|
greeting_->setText("Hello there, " + nameEdit_->text());
|
|
}
|
|
|
|
WApplication *createApplication(const WEnvironment &env) {
|
|
return new HelloApp(env);
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
return WRun(argc, argv, &createApplication);
|
|
}
|
|
|
|
|