Support #4490
closedconnection to pushbutton does not work
0%
Description
Hello together,
modifying the code used for the Wt homepage like below does show the button and the edit field but
the action of the button (showDialog()) is not triggered.
WWidget *WtHome::example(const char *textKey, const std::string& sourceDir)
{
WContainerWidget *result = new WContainerWidget();
result->addWidget(linkSourceBrowser(sourceDir));
Wt::WTemplate *t = new Wt::WTemplate(tr(textKey), result);
t->setInternalPathEncoding(true);
t->bindWidget("name-edit", new Wt::WLineEdit());
Wt::WPushButton *saveButton = new Wt::WPushButton("Save", result);
t->bindWidget("save-button", saveButton);
Wt::WText *out = new Wt::WText(result);
out->setStyleClass("help-block");
saveButton->clicked().connect(std::bind([=] () {
showDialog(out);
}));
return result;
}
void WtHome::showDialog(Wt::WText *out)
{
Wt::WDialog *dialog = new Wt::WDialog("Go to cell");
...
dialog->show();
}
Greetings
Updated by Koen Deforche about 9 years ago
- Status changed from New to Feedback
Hey,
It looks like it should work. Can you attach the complete modified sources so that can investigate?
Koen
Updated by Vassilios Kotaidis about 9 years ago
Hello Koen,
I checked saveButton->clicked().isConnected(), it returns true.
But I found the problem after trying around :)
original code where showDialog() is not triggered:
examplesMenu_
addTab(wrapView(&WtHome::loadData),tr("load-data"))>setPathComponent("");
new code where showDialog() is triggered:
examplesMenu_
addTab(loadData(), tr("load-data"))>setPathComponent("");
The difference is explained in a comment in the file WtHome.cpp (see below).
So, wrapView() does not disconnect the signal, but prevents it from being triggered. Design error of wrapView()?
Greetings
Vassili
/*
- The following code is functionally equivalent to:
- examplesMenu_->addTab(loadData(), "Hello world");
- However, we optimize here for memory consumption (it is a homepage
- after all, and we hope to be slash-dotted some day)
- Therefore, we wrap all the static content (including the tree
- widgets), into WViewWidgets with static models. In this way the
- widgets are not actually stored in memory on the server.
*/
Updated by Koen Deforche about 9 years ago
- Status changed from Feedback to Resolved
Hey,
That's indeed a gotcha, but it's correct. A connected signal only works if the 'signal' still exists server-side, which isn't the case for a wrap-view'ed widget.
Koen
Updated by Koen Deforche about 9 years ago
- Status changed from Resolved to Closed
Updated by Koen Deforche about 9 years ago
- Target version changed from 3.3.4 to 3.3.5