Project

General

Profile

Simple Hello World not working

Added by Adam Skluzada about 7 years ago

Hello,

here is my Hello World code:

#include <Wt/WApplication.h>
#include <Wt/WPushButton.h>
#include <Wt/WText.h>
using namespace Wt;

class HelloApplication : public WApplication{
public:
  HelloApplication(const WEnvironment & env);
};

HelloApplication::HelloApplication(const WEnvironment & env)
:WApplication(env){
  root()->addWidget(cpp14::make_unique<Wt::WText>("Hello World!"));
}

WApplication * createApplication(const WEnvironment & env){
  return new HelloApplication(env);
}

int main(int argc, char ** argv){
  return WRun(argc, argv, &createApplication);
}

First, I would like to ask about the addWidget function. Tutorials I've seen online used it with (New WText("Hello World!") as an argument, but when I try this, the compiler returns an error:

error: no matching function for call to ‘Wt::WContainerWidget::addWidget(Wt::WText*)’

I've figured out that I have to use (cpp14::make_uniqueWt::WText("Hello World!") as an argument instead, but I would like to understand why is the previous argument wrong according to my compiler despite beeing suggested in tutorials.

And an second error, which I don't know how to solve is with the WRun function:

error: could not convert ‘createApplication’ from ‘Wt::WApplication* (*)(const Wt::WEnvironment&)’ to ‘Wt::ApplicationCreator {aka std::function<std::unique_ptr<Wt::WApplication>(const Wt::WEnvironment&)>}’

Both errors confuse me as the code is basically a copypaste from an online tutorial.

I am using g compiler version 7.3.1-2 with arguments -lwt -lwthttp

Wt version 4.0.3-rc1 and boost libary version 1.63

Thank you for any help, I'm just a very confused beginner and the errors doesn't really tell me much.


Replies (1)

RE: Simple Hello World not working - Added by lm at about 7 years ago

Wt version 4 changed much of Wt so that instead of passing raw pointers about, they're generally passed as std::unique_ptr. The example you saw suggesting addWidget(new Wt::WText) is outdated. Where did you see it?

Likewise, you need to change your createApplication to the following:

std::unique_ptr<WApplication> createApplication(const WEnvironment & env){
  return std::make_unique<WApplication>(env);
}

You should use the documentation: https://www.webtoolkit.eu/wt/doc/reference/html/namespaceWt.html as your go-to. It is generated from source, so the synopses are correct. (The comments are sometimes out of date, too.)

Your gcc appears to be pretty recent; what distribution are you using?

    (1-1/1)