Project

General

Profile

How do I get a WServer instance from my app?

Added by Ivan Reche about 1 year ago

I'm trying to configure Wt's logger to understand why my application is crashing upon booting. It's the example Hello World application. I'm using Visual Studio on Windows.

I understand that I can get a logger instance from my WServer instance, but I can't seem to find how to get the WServer instance associated with my app.

The code is the one from the docs:

#include <Wt/WApplication.h>
#include <Wt/WBreak.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
#include <Wt/WText.h>

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

private:
    Wt::WLineEdit *nameEdit_;
    Wt::WText *greeting_;
};

HelloApplication::HelloApplication(const Wt::WEnvironment& env)
    : Wt::WApplication(env)
{
    setTitle("Hello world");

    root()->addWidget(std::make_unique<Wt::WText>("Your name, please? "));
    nameEdit_ = root()->addWidget(std::make_unique<Wt::WLineEdit>());
    Wt::WPushButton *button = root()->addWidget(std::make_unique<Wt::WPushButton>("Greet me."));
    root()->addWidget(std::make_unique<Wt::WBreak>());
    greeting_ = root()->addWidget(std::make_unique<Wt::WText>());
    auto greet = [this]{
      greeting_->setText("Hello there, " + nameEdit_->text());
    };
    button->clicked().connect(greet);
}

int main(int argc, char **argv)
{
    return Wt::WRun(argc, argv, [](const Wt::WEnvironment& env) {
      return std::make_unique<HelloApplication>(env);
    });
}

My app always crashes with a Wt::WServer::Exception, but I can't see its contents on Visual Studio.


Replies (2)

RE: How do I get a WServer instance from my app? - Added by Ivan Reche about 1 year ago

Well, my crash was because I wasn't linking against wthttp (I was linking only against wt), so that's solved, but my question remains and might be useful to others. :)

RE: How do I get a WServer instance from my app? - Added by Roel Standaert about 1 year ago

It's strange to me that you didn't get a linker error, and instead got an exception.

    (1-2/2)