Project

General

Profile

Web Page Blank Page

Added by umer umer over 4 years ago

i'm using these examples. [[[https://www.webtoolkit.eu/widgets/navigation/menu]]].

it's compiled well but not showing any this except title of the page.

my code is:

#include <Wt/WApplication.h>
#include <Wt/WBreak.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WMenu.h>
#include <Wt/WStackedWidget.h>
#include <Wt/WTextArea.h>

//using namespace Wt

class WMenu:public Wt::WApplication{
   private:
        int abc=1;
   public:
        WMenu(const Wt::WEnvironment& env);   //constructor
};

WMenu::WMenu(const Wt::WEnvironment& env):Wt::WApplication(env)

{
   setTitle("this is test");
   auto container = Wt::cpp14::make_unique<Wt::WContainerWidget>();

   // Create a stack where the contents will be located.
   auto contents = Wt::cpp14::make_unique<Wt::WStackedWidget>();

   Wt::WMenu *menu = container->addNew<Wt::WMenu>(contents.get());
   menu->setStyleClass("nav nav-pills nav-stacked");
   menu->setWidth(150);
// Add menu items using the default lazy loading policy.
   menu->addItem("Internal paths", Wt::cpp14::make_unique<Wt::WTextArea>("Internal paths contents"));
   menu->addItem("Anchor", Wt::cpp14::make_unique<Wt::WTextArea>("Anchor contents"));
   menu->addItem("Stacked widget", Wt::cpp14::make_unique<Wt::WTextArea>("Stacked widget contents"));
   menu->addItem("Tab widget", Wt::cpp14::make_unique<Wt::WTextArea>("Tab widget contents"));
   menu->addItem("Menu", Wt::cpp14::make_unique<Wt::WTextArea>("Menu contents"));

   container->addWidget(std::move(contents));
}
int main(int argc, char **argv)
{
    return Wt::WRun(argc, argv, [](const Wt::WEnvironment& env) {
      return std::make_unique<WMenu>(env);
    });
}

Please let me know what's wrong with this code?


Replies (2)

RE: Web Page Blank Page - Added by Roel Standaert over 4 years ago

Hey,

I'm noticing two things:

It's kind of odd that you named your WApplication WMenu. That's a bit confusing, but not what's causing your issue.

Your problem is that you did create a container, but that goes out of scope at the end of your WMenu constructor. It's never added to the widget tree. You'll need to add that container to the WApplication's root().

Regards,

Roel

RE: Web Page Blank Page - Added by umer umer over 4 years ago

thanks. got it brother :)

Actually, I'm new in WT.

I have changed the App name.

    (1-2/2)