Reputation:
Im currently learning C++ and Im interested in a web front end that can be fast as its C++ back end part. Which front ends does make a good combination?
Not looking for the best just the ones that can join cpp without using cgi.
---Update------
I actually develope my web applications in Java and is nice. Im looking at the C++ side since I want to give it a try. I learn a little of C++ on a college class 3 years ago and now Im reading the Deitel 8th Edition book to cover what I miss and review what I previosly learned. I'll read all your suggestions and will select a balance between productivity and speed. I admit it I am a performace addict that's the reason of my interest on this. Before asking this I thought Python could be used as a web front end. But maybe its not near C++ performance and thats why you didnt mentioned it.
-----Update #2------
What behaivor could have using python web frameworks or java servlets for the web engine and then connect it to C++? Will tomcat or the python server be a bottleneck?
Upvotes: 0
Views: 8259
Reputation: 5629
Having done research, I can tell that as of writing the words there isn't a good solution for writing a web frontend in C++, Rust, etc. Existing ones break to two types:
WebAssembly/emsdk/emscripten: this includes at least Qt, Rinf and Dear ImGui. Problems they suffer from:
You can work around it by making a separate backend that would communicate to the frontend via websockets, but that increases the effort.
Actually supporting web as target: Gtk and Flutter. Unfortunately, they both suffer from the same problem: no text they generate is searchable. Issue for Flutter.
In my opinion it's a deal-breaker, because browser's "find on page" is a thing people use many times per day. Search implemented by the site won't cover it, because the usecases are orthogonal. For example, it would be odd to implement a search that would simply find a button with certain text on the page.
With that said, below is a tutorial for Gtk (being my old answer) in case someone will find it useful.
Gtk allows targeting web via its "broadway" backend. It works like this: first you run GTK broadwayd server, and then you run your app by passing it env. variables to connect to to the server. In my experiments works fine without graphics, as you'd expect.
By default server serves http
. To make it use https
generate certificates and pass to broadwayd server two paths -c cert.pem -k key.pem
.
Here's a simple hello world web frontend via Gtk:
test.cpp
with the following content:
#include <gtk/gtk.h>
static void activate(GtkApplication *app, gpointer user_data) {
GtkWidget *window = gtk_application_window_new(app);
// web frontend can't have top bar and be non-maximized
gtk_window_maximize(GTK_WINDOW(window));
gtk_window_set_decorated(GTK_WINDOW(window), false);
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_halign(box, GTK_ALIGN_CENTER);
gtk_widget_set_valign(box, GTK_ALIGN_CENTER);
gtk_window_set_child(GTK_WINDOW(window), box);
GtkWidget *button = gtk_button_new_with_label("Hello World");
gtk_box_append(GTK_BOX(box), button);
gtk_window_present(GTK_WINDOW(window));
}
int main(int argc, char **argv) {
GtkApplication *app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
int status = g_application_run(G_APPLICATION(app), argc, argv);
g_object_unref(app);
return status;
}
g++ test.cpp -o a $(pkg-config --cflags --libs gtk4) -g3 -O0
gtk4-broadwayd -p 8085
GDK_BACKEND=broadway ./a
Be warned though, Gtk developers consider the backend experimental. Quoting them from IRC:
[14:21:32] <mclasen> a good reminder that we should document broadway more clearly as an experiment [14:26:10] <mclasen> it was written as a one-off experiment, and is not actively developed [14:26:37] <mclasen> it works and supported the gtk 4.0 features, but it is falling behind newer developments [14:37:14] <ebassi> […]: what mclasen said. Broadway is an experiment [14:37:25] <ebassi> if you want to use it, you get to fix it
Upvotes: -1
Reputation: 120
I think it's hard to find a web front end in C++ (probably what you are looking for is a C++ equivalent of GWT). Back ends are more common and there're some frameworks to create web apps in C++. Facebook has Hiphop for converting PHP code to C++ to speed up. But everything mostly boils down to HTML(5)/JavaScript/CSS. However, Qt framework has integration with WebKit and you can build applications using this framework which leverages HTML5/JavaScript/CSS3 in a C++ app (I'm not too familiar with it, so may be wrong). Take a look at this by the way.
EDIT: On further googling, found Wt, this might look interesting. :)
Upvotes: 0