Project

General

Profile

Code-Example that won't work for me

Added by Quirin Schwanse over 5 years ago

Hey there, tried to write a simple test-application to get familiar with Wt, should actually work but

it seems that I forgot something, can someone just read over this and tell me where I'm wrong? Thank you! _

main.cpp:

[code]

#include "Template.h"

int main(int argc, char *argv[]) {

return Wt::WRun(argc, argv, [](const Wt::WEnvironment &env) {

auto app = std::make_uniqueWt::WApplication(env);

app->messageResourceBundle().use("approot/templates"); //loading templates.xml for messages

app->messageResourceBundle().use("approot/strings_de"); //loading strings_de.xml for messages

app->useStyleSheet("docroot/style.css"); //loading style.css for used stylesheet

app~~root()~~>addNew();

return app;

});

}

[/code]

Template.h:

[code]

#pragma once

#include "Navigation.h"

#include <Wt/WTemplate.h>

class Template : public Wt::WTemplate

{

public:

Template();

};

[/code]

Template.cpp:

[code]

#include "Template.h"

Template::Template() : WTemplate{ tr("tpl.template") }

{

addFunction("tr", &WTemplate::Functions::tr);

auto test = bindWidget("test", std::make_unique());

}

[/code]

Navigation.h:

[code]

#pragma once

#include <Wt/WTemplate.h>

#include <Wt/WApplication.h>

#include <Wt/WLineEdit.h>

#include <Wt/WPushButton.h>

#include <Wt/WText.h>

#include <Wt/WContainerWidget.h>

class Navigation : public Wt::WContainerWidget

{

public:

Navigation(const std::string &name);

private:

std::string name_;

Wt::WPushButton *B_Home;

Wt::WPushButton *B_Discover;

Wt::WPushButton *B_Profile;

};

[/code]

Navigation.cpp:

[code]

#include "Navigation.h"

Navigation::Navigation(const std::string &name) : name_(name)

{

setContentAlignment(Wt::AlignmentFlag::Right);

B_Home = addWidget(std::make_uniqueWt::WPushButton(tr("str.home")));

B_Discover = addWidget(std::make_uniqueWt::WPushButton(tr("str.discover")));

B_Profile = addWidget(std::make_uniqueWt::WPushButton(tr("str.profile")));

}

[/code]

templates.xml:

<?xml version="1.0" encoding="utf-8"?>





${test}


strings_de.xml:

<?xml version="1.0" encoding="utf-8"?>



Home

Erkunden

Profil


Replies (3)

RE: Code-Example that won't work for me - Added by Quirin Schwanse over 5 years ago

omgosh sorry for the bad formatting :<

RE: Code-Example that won't work for me - Added by lm at over 5 years ago

This is a fairly bad way to ask a question. Be sure to add what you expect to happen and what actually happens for you. Also, let us know how to set things up to run your example. It's nice when the example is in as few files as possible, but this isn't terrible in that regard. Of course...here I am answering though :shrug:

Wrap extended code examples in < pre>< /pre>@ (with no internal space).

In Template.cpp, you attempt to instantiate a Navigation without supplying any parameters to the constructor. After fixing that, and placing the two .xml files in ./approot/, it works for me (screenshot attached).

wt.png (6.16 KB) wt.png

RE: Code-Example that won't work for me - Added by Quirin Schwanse over 5 years ago

Hey, thanks for the feedback, I actually thought about the way u mentioned right after I posted

my bad thread, sorry for that!

Actually makes a lot of sense, since I had the standard constructor implemented without instantiating the Objects, so

just stupid me :<

Thank you! Works for me now with your Solution :>

    (1-3/3)