
Wt – C++ Web Toolkit - gtirloni
https://www.webtoolkit.eu/wt
======
afranchuk
I used Wt about a year ago for an application at work. I was able to write a
GUI program that could be accessed at a web address or with a native Qt
application, and Wt was equivalent enough (API-wise) that I was able to
template between the two. Really neat actually. There was one place where the
GUI was defined and you could choose whether you wanted web, native, or both!
Only stumbling block was when I needed some opengl (webgl), but with a fairly
minimal abstraction I was and to get that working in both two.

Wt felt very polished and worked exactly as I expected.

~~~
guruz
A propos Qt.

There is Qt for Web Assembly. [https://www.qt.io/qt-examples-for-
webassembly](https://www.qt.io/qt-examples-for-webassembly)

And WebGL streaming [https://www.qt.io/blog/2018/11/23/qt-quick-webgl-
release-512...](https://www.qt.io/blog/2018/11/23/qt-quick-webgl-
release-512#what-is-webgl-streaming)

~~~
mwcampbell
The Qt port for WebAssembly still has zero accessibility support, e.g. for
blind people with screen readers. Assuming Wt is using standard HTML form
controls, it shouldn't get in the way of accessibility. Of course, the app
developer still needs to follow good accessibility practices, such as labeling
images and not conveying information through color alone.

~~~
pjmlp
While it is unfortunate, in 30 years of software development that has never
been a requirement for the projects I have been involved unless the customer
was some kind of governmental institution and made it part of the acceptance
criteria.

So unless there is a mindset change, that will keep happening.

~~~
kitd
Seriously?

Not just govs, but just about all large orgs serving web apps have
accessibility requirements.

~~~
pjmlp
Depends pretty much on your jurisdiction, then in many countries even if that
is required by law, trying to make a lawsuit out of it will lead nowhere, as
most countries aren't so lawsuit friendly as US.

Assuming that there is a court willing to hear it, probably by the time it
reaches the first audience there is a new website in place.

------
nikki93
With 'modern C++' you can make APIs way nicer than the Java-like API going on
here. Lambdas really help, along with RAII which has already been around. I
have an API going where the following syntax creates a div with a 'toolbar'
class and a toggle button with the 'edit' class and updates the DOM (C++
running in WASM, using IncrementalDOM for the DOM access):

    
    
      ui.div()("toolbar")([&]() {
        ui.button()("edit")("selected", editing)("click", [&](emscripten::val target) {
          editing = !editing;
        });
      });
    

This works by having `.div()` etc. return an `Elem` type whose constructor
opens an HTML element and destructor closes it, with various overloads of
`operator()` letting you set attributes, bind events or add child elements.

Here's a video of some results with C++ and CSS:
[https://twitter.com/snikhilesh/status/1279913032471031809](https://twitter.com/snikhilesh/status/1279913032471031809)

I should do a writeup about this soon...

~~~
jordigh
So what do the compiler errors look like when you mess this up? Say, you use
the wrong argument passing for one of the lambdas.

~~~
suls
Exactly what I came here to say.

The error messages produced by g++ for anything template related are a really
difficult hurdle to overcome as a beginner. I am sure once you mastered it, it
does make sense -- but right now it's a source of frustration for me.

~~~
pjmlp
concepts will fix that.

For the time being, any library writer can improve their own error messages
using a mix of constexpr if, static_assert and enable_if.

~~~
nikki93
Yeah I'm looking forward to seeing how concepts work out in practice.

Also, to clarify on the original point, in this case it doesn't require that
much template trickery. Most attributes could be handled as
`.foo(Foos::BAR_1)` to set HTML attribute `foo="bar_1"` for example and have
things still be 'type safe' on the C++ side. I just pass strings through right
now to have a catch-all API, then I could go back on it after some real use
and see what styles come in practice.

The only template it happens to use right now is the usual `template<typename
F>` with `F &&f` to let you pass an inlineable lambda. I could use
`static_assert` as you say, with `std::is_invocable_v`, and offer a nicer
error message when that doesn't match.

------
stjo
Making a front end library/framework/toolkit without screenshots and example
code should be made punishable by law.

~~~
beached_whale
The whole site is run on it, and your working examples are there just had to
click on documentation
[https://www.webtoolkit.eu/wt/documentation](https://www.webtoolkit.eu/wt/documentation)

~~~
stjo
Oooh, that's nice

------
dang
If curious see also

2013
[https://news.ycombinator.com/item?id=5997034](https://news.ycombinator.com/item?id=5997034)

2010
[https://news.ycombinator.com/item?id=1098282](https://news.ycombinator.com/item?id=1098282)

2009
[https://news.ycombinator.com/item?id=886900](https://news.ycombinator.com/item?id=886900)

------
Jeaye
I tried using Wt for a site almost a decade ago, it seems. The layout managers
would make the site so terribly jittery that it could cause motion sickness.

My use case for Wt at the time as "I know C++ well and I don't want to learn
anything else." I don't think I'll ever have a better use case for it and I
don't think that one was very good to begin with.

The best use case I can imagine is something like "We have a lot of existing
C++ code which we need to turn into a web app." But even then, why does the
C++ code need to manage the DOM? It almost certainly doesn't.

------
juangburgos
WrDesigner author here. I started the QtDesigner-like tool for Wt because I
had a project where I needed to expose some existing C++ code on to the web.
In the end I never used it. As I learnt web technologies, I found much
flecible and easier to expose an API to the web using QWebChannel and then do
the frontend with one of the existing frameworks (Vue, React, etc).

------
doteka
While certainly impressive, the Hello World example in their documentation is
in no way preferable to writing JavaScript.

------
c-smile
Am I right that this is close to ASP.NET thing

    
    
       <asp:textbox text="hello world" runat=server />
    

In particular to that runat=server part?

So widget gets rendered to HTML on server side with events sent to it from
client? That may work for logical events like click but not for mousemove (too
expensive) ...

------
cocoa19
It's hard to compete with Open Source Libre libraries and lower C++ interest
in new developers, not to mention developing in C++ is harder than many other
languages.

My employer still struggles to this day finding good recent grads remotely
interested in C++. In contrast, Java and Javascript skills are easy to find in
the market.

Edit: Added "Libre"

~~~
zelly
C++ people don't do CRUD webshit. C++ is for compilers, HFT, machine learning,
browsers, search engines, robotics. When C++ touches "the web" it's in the
form of something like Envoy or HAProxy, not exactly application layer. For
CRUD webshit, there are literally hundreds of options out there that largely
automate the entire process (Rails/Django/Spring). There is no reason to use
C++ for it not just because of the timesink but because the lack of safety
makes it an aggressively bad idea. You would get all kinds of "I thought that
wasn't a problem in the 21st century anymore" type of problems.

~~~
fbmac
That's the illusion that got me into C. Reality I found is, where I live at
least, C is for legacy code and code that runs in very bad hardware.

~~~
zelly
What illusion are you talking about?

------
cbsmith
I always liked Wt. I haven't used it in quite a while. What's it like these
days?

------
einpoklum
So, Wt is about having the server do a bunch of computational work for
rendering the UI. Now, I'm not a web developer, so I may be talking nonsense,
but I don't see how that's reasonable:

1\. It doesn't scale, or if you're rich - it's annoying to scale. 2\. It
interferes with the client/user's ability (albeit theoretical) to decide how
they want to present the information 3\. It seems to go against what are, or
used to be, the principles of the web: Interlinked, clear-text, markup which
the client renders as it sees fit.

~~~
roywiggins
The Wt backend spits out HTML/JS (or sometimes PDF or svg for charts), like
any other server-side framework. It's not replacing the browser's renderer.

~~~
einpoklum
<html> <body> <img src="/path/to/my/rendered_output.png"> </body> </html>

This is also spitting out HTML...

------
jokoon
Wait, is this using http/html, or something else? I'm not sure I understand
the "web" part in this.

~~~
nephanth
It is. But it is abstracting over http/HTML/JavaScript/rpc(ajax) with c++
classes

------
piyush_soni
Isn't this like C# with ASP.Net? Or is there any other benefit to it?

~~~
pjmlp
ASP.NET doesn't run everywhere where there is a C++ compiler, including
embedded devices.

------
varbhat
What's the real advantage of using this over HTML template rendering?

~~~
rsecora
I will try to be brief and go to the point.

Wt is different to templating. It's server side rendering and the widgets
communication is transparent, based on slots and receivers in the server side.

If you came from java it has similarities to Vaadin.

It has more goodies, websockets, DB...

------
mjs33
Is this just CGI?

~~~
pgquiles
Kind-of, but you write webapps as if you were writing desktop apps: widgets,
layouts, etc.

Wt can be compiled to its own webserver (which you would use directy if on an
embedded device oruse behind a reverse-proxy for other cases), or you can
compile it to a FastCGI module you can run with Apache.

------
marta_morena_25
I find it irritating that even after reading their front-page and the "How you
can use WT" I still have no clue what it is supposed to be. Is this an
embedded browser? Is it a C++ app GUI that allows you to use HTML like
construction? Is it an emscripten application? How can it work without JS
enabled? Is it compiled into pure WebASM? What the heck do they mean by
connection? What connection? What does have PDF and DB to do with all that?
Etc.

Very poor marketing imo. After reading all this I have even less clue what it
is supposed to do.

~~~
roywiggins
It works without JavaScript because it can render everything server-side. If
the user has JavaScript it uses websockets or Ajax to fetch updates from the
server, but if it doesn't have those it can just reload the whole page like
you would with a CGI application.

"Qt, but for web applications" would be a short and basically accurate
descriptor. You slot together widgets in C++ and it works out how to lay them
out and connect actions taken by the user to your event-handling code, which
lives on the server.

The PDF thing is for rendering reports to PDF, instead of HTML. Not useful
unless you're in a corporate sort of space, but when you want a PDF report you
do want something like that. The DB thing is an ORM that makes basic CRUD
operations on your database easier.

~~~
hellofunk
Oh strange, I completely assumed from the start that it was referring to front
end C++ using Webassembly, similar to how some rust libraries do it. Never
occurred to me this is server side.

~~~
chrismorgan
Wt comes from many years before WebAssembly.

------
briandilley
painful

------
shayas
Why some people can't liberate themselves from C++?

~~~
PaulDavisThe1st
Because we're already free.

~~~
znpy
Best comment

