Project

General

Profile

Bug #6235

Wt4.0.2: In certain case, removeFromParent() is not working.

Added by Apivan Tuntakurn over 4 years ago. Updated over 4 years ago.

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);
      }
    }
  }

Also available in: Atom PDF