Hey Dave,
> Taking your hint, I am trying to skip Intermediate.wt and just use
>
> Login.html --> Schedule.wt
>
> I create an WHBoxLayout which holds a WMenu on the left and a WStackedWidget
> on
> the right (this is the form of the presentation in Schedule.wt, so I am just
> setting it up early). I add a single WMenuItem which is a WContainerWidget to
> hold some instructions as a WText, a WCombobox which lists the allowed
> databases the user has access to, and a WPushButton to confirm their choice. I
> attach a callback to WPushButton.clicked() which tries to remove the single
> menu entry I've just set up, and add a bunch of menu entries which are the
> substance of Schedule.wt.
>
> The problem is, when WPushButton is pushed and I try to remove the single menu
> entry, the program dies. I guess this doesn't surprise me, because the
> WPushButton is a child widget of the single menu item. So, during the
> callback,
> I am removing the parent of the widget which has the callback. Is there a way
> around this? The workaround I am now using is just to hide the first menu
> entry.
That really should work though. A signal can handle being deleted
while it is emitted, and Wt's widgets also are aware that they may be
deleted when emitting a signal.
I tried your test case and could not reproduce the bug. I did however
that the destructor of WMenuItem did not properly clean up memory
(fixed in latest git, or with the following patch):
diff --git a/src/Wt/WMenuItem.C b/src/Wt/WMenuItem.C
index 0d2bb09..6f9b2e5 100644
--- a/src/Wt/WMenuItem.C
+++ b/src/Wt/WMenuItem.C
@@ -57,6 +57,9 @@ WMenuItem::~WMenuItem()
{
if (menu_)
menu_->removeItem(this);
+
+ delete itemWidget_;
+ delete contents();
}
In attachment your code converted to a test case. As you can see, I
simplified the code (although the original ran fine too): simply
deleting the item will do what you want it to do (including deleteing
all the associated contents of the chooseDBContainer_).
If you are running on Linux, can you show the output of valgrind of your crash ?
Regards
koen
#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <Wt/WContainerWidget>
#include <Wt/WComboBox>
#include <Wt/WHBoxLayout>
#include <Wt/WMenu>
#include <Wt/WMenuItem>
#include <Wt/WPushButton>
#include <Wt/WStackedWidget>
#include <Wt/WText>
using namespace Wt;
class ScheduleApplication : public WApplication
{
public:
ScheduleApplication(const WEnvironment& env);
private:
WContainerWidget *chooseDBContainer_;
WComboBox *chooseDBComboBox_;
WMenu *menu_;
WStackedWidget *menuContainer_;
WPushButton *chooseDBPushButton_;
WMenuItem *chooseDBMenuItem_;
void Database_Chosen();
};
ScheduleApplication::ScheduleApplication(const WEnvironment& env) : WApplication(env) {
setTitle("Scheduling");
setCssTheme("polished");
menuContainer_= new WStackedWidget;
menuContainer_->setOverflow(WStackedWidget::OverflowAuto);
menuContainer_->setPositionScheme(Relative);
menuContainer_->setStyleClass("contents");
menu_ = new WMenu(menuContainer_,Vertical,0);
menu_->setRenderAsList(true);
menu_->setStyleClass("menu");
menu_->setInternalPathEnabled();
menu_->setInternalBasePath("/");
useStyleSheet("....../everywidget.css");
WHBoxLayout *horizontalLayout_ = new WHBoxLayout(root());
chooseDBContainer_ = new Wt::WContainerWidget;
chooseDBContainer_->resize(WLength::Auto, 400);
WText *chooseDBInstructions;
chooseDBComboBox_ = new WComboBox;
chooseDBComboBox_->addItem("scheduling");
chooseDBComboBox_->addItem("foo_bar_bletch");
chooseDBContainer_->addWidget(chooseDBInstructions
=new WText("Please select the schedule database you wish to work on:<br />"));
chooseDBContainer_->addWidget(chooseDBComboBox_);
chooseDBContainer_->addWidget(new WBreak);
chooseDBPushButton_ = new Wt::WPushButton("OK");
chooseDBPushButton_->clicked().connect(this,
&ScheduleApplication::Database_Chosen);
chooseDBContainer_->addWidget(chooseDBPushButton_);
chooseDBMenuItem_=menu_->addItem("foo2",chooseDBContainer_);
horizontalLayout_->addWidget(menu_,0);
horizontalLayout_->addWidget(menuContainer_,1);
}
void ScheduleApplication::Database_Chosen(void){
std::string db_name_=chooseDBComboBox_->currentText().toUTF8();
delete chooseDBMenuItem_;
//Setup_Scheduling_Page();
}
WApplication *createApplication(const WEnvironment& env)
{
return new ScheduleApplication(env);
}
int main(int argc, char **argv)
{
return WRun(argc, argv, &createApplication);
}
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest