Actions
Bug #6235
openWt4.0.2: In certain case, removeFromParent() is not working.
Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
02/15/2018
Due date:
% Done:
0%
Estimated time:
Description
If I understand correctly, widget->removeFromParent() is supposed to be a replacement for "delete widget".
// This works.
{
Test::WTestEnvironment environment;
auto app = std::make_unique<Wt::WApplication>(environment);
{
auto layout = app->root()->setLayout(std::make_unique<Wt::WVBoxLayout>());
auto testWidget = layout->addWidget(std::make_unique<Wt::WLabel>());
auto removedItem = testWidget->removeFromParent();
if (removedItem == nullptr)
{
assert(false);
}
}
}
// This does not work.
{
Test::WTestEnvironment environment;
auto app = std::make_unique<Wt::WApplication>(environment);
{
app->root()->setLayout(std::make_unique<Wt::WVBoxLayout>());
auto testWidget = app->root()->addNew<Wt::WLabel>("test");
auto removedItem = testWidget->removeFromParent();
if (removedItem == nullptr)
{
assert(false);
// found item to be removed, but the app eventually crashed.
auto removedItem2 = app->root()->removeChild(testWidget);
}
}
}
Updated by Apivan Tuntakurn about 6 years ago
// This does not work either.
{
Test::WTestEnvironment environment;
auto app = std::make_unique<Wt::WApplication>(environment);
{
app->root()->setLayout(std::make_unique<Wt::WVBoxLayout>());
auto p = std::make_unique<Wt::WObject>();
auto testObject = p.get();
app->root()->addChild(std::move(p));
auto conChild = testObject->addChild(std::make_unique<Wt::WContainerWidget>());
auto removedItem = conChild->removeFromParent();
if (removedItem == nullptr)
{
assert(false);
// found item to be removed, but the app eventually crashed.
auto removedItem2 = app->root()->removeChild(conChild);
}
}
}
Updated by Roel Standaert about 6 years ago
Not sure about the second case, in the third case removedItem
is definitely supposed to be null, since you're never actually putting the WContainerWidget
in the widget tree.
Updated by Apivan Tuntakurn almost 6 years ago
Thank you for reply. In the third case, I did not notice that removeFromParrent() is implemented in Wt::WWidget and not the Wt::WObject. So, you can drop this case.
Personally, I think the name removeFromParrent is slightly too generic that I mixed addChild() and addWidget() up.
Actions