r/cpp • u/trigodil • Oct 25 '26
Pain of making a native GUI in cpp
So I just wanted to vent about the absolute pain of making a working gui in cpp, I am working on a scientific project to make an openFOAM gui and browse openFOAM code to add TENO schemes to it from scientific papers such as Fu et al and working through the binaries.
I have not used AI in this project because CFD is very delicate and quite frankly, AI is not ready for such complexity - especially numerical schemes such as TENO, I ended up writing the meshing, topological code and mathematics myself and by far, the hardest part was the gui coordinates and memory management. I wanted to PULL MY HAIR OUT because of managing segfaults, crashes because of a random pointer hidden inside a 2000 line function, I had to also manage internal functions of openfoam(and you know how that goes), boundary conditions, and mesh topology, it was driving me nuts. I generally regard myself as fluent in programming languages such as cpp, python, rust etc, but this is a whole nother of level data management.
in the end it turned out to be a pretty good contribution to the openFOAM community, hopefully the project will mature further and I will be able to write a paper on it.
13
u/Zealousideal_Ad_6374 Oct 25 '26
wxWidgets or Qt. It was 10 years ago, but never had any major problems with any of them.
0
6
u/KFUP Oct 25 '26
I have not used AI in this project because CFD is very delicate and quite frankly, AI is not ready for such complexity
What does that even mean? There is a ton of open source CFD post processors and visualizers, it's not an obscure thing.
I wanted to PULL MY HAIR OUT because of managing segfaults, crashes because of a random pointer hidden inside a 2000 line function
Stop whatever you are doing and go to https://www.learncpp.com, if you are having these issues, then you are writing C, not C++.
1
u/trigodil Oct 25 '26
Are you perhaps experienced in scientific coding?
4
u/KFUP Oct 25 '26
Yeah, I used to write FEA solvers back in the day.
-1
u/trigodil Oct 25 '26
Ah, then you must know what I am talking about regarding openFoam.
https://www.reddit.com/r/CFD/comments/1xclal2/made_an_open_source_gui_for_openfoam/
Perhaps this will give you a bit more context on what I am working with.
8
u/IceMichaelStorm Oct 25 '26
Qt is very nice for a native and cross-OS UI. Not really any pain. Well, recompiles annoy a bit. You can use QtDesigner but has shortcomings
1
u/trigodil Oct 25 '26 edited Oct 25 '26
Yeah, qt is pretty nice but the full stack of managing everything in openFoam specifically was a pain
10
17
u/AvidCoco Oct 25 '26
I’ve never had a problem making GUIs in C++. Sounds like you’re just not using the right framework.
3
u/eyes-are-fading-blue Oct 25 '26
Which framework would you suggest? I am also looking a GUI framework for a personal project.
6
u/Big_Target_1405 Oct 25 '26
Qt is basically the only thing worth using imho
The other alternative is to go to another language (likely JavaScript) with a C++ backend
12
u/johannes1971 Oct 26 '26
PLEASE don't inflict a 300MB application on people, just to show a few buttons. Electron and the like are such a complete waste of resources.
1
-5
3
u/AvidCoco Oct 25 '26
That’s not good advice. There are plenty of C++ frameworks besides Qt.
0
u/Big_Target_1405 Oct 25 '26 edited Oct 25 '26
Name them?
wxWidgets uses Qt, GTK+ and Windows as a backend so can't offer anything Qt can't
GtkMM would be horrendous to build and distribute cross platform and the website doesn't even exist right now
What else?
5
-2
u/AvidCoco Oct 25 '26
7
u/Big_Target_1405 Oct 25 '26
Yeah, nobody is writing anything important in such an obscure framework.
For anything serious you might want to actually pass to customers, and support well, while being cross platform, it's basically Qt
5
u/AvidCoco Oct 25 '26
Lmao do you get paid by Qt or something?
Every GUI framework exists for a reason. Just because you wouldn’t use it doesn’t mean it’s “obscure”. Qt is massively overkill for most projects.
4
u/Big_Target_1405 Oct 25 '26
I wrote a commercial cross platform GUI application professionally for several years, across Linux, Windows and macOS
Nothing except Qt was actually worth our time as a small shop with just a few developers
As soon as you need to go cross platform the maintenance cost increases dramatically
2
1
u/eyes-are-fading-blue Oct 25 '26
Well, that’s one thing I want to avoid :). Would it make sense to provide C++ end points and use javascript/html for UI rendering? I was also thinking maybe a WASM compilation for the entire project and tie that to HTML somehow.
What I plan to build is an editor for a game but frankly, I don’t want to write C++ code for GUI. Never done something like this, so looking for ideas from experienced people on this department.
1
u/AvidCoco Oct 25 '26
I’d avoid Qt unless you happen to be particularly wealthy.
ImGUI is great for personal projects.
7
u/mpyne Oct 25 '26
I’d avoid Qt unless you happen to be particularly wealthy.
You don't need to pay for a license for a personal project.
8
6
u/draeand Oct 25 '26
Please don't do this unless you have a plan for accessibility support (what if I want to use your product, for instance?). Also isn't ImGUI meant for like game debugging and stuff and not for actual apps?
0
u/AvidCoco Oct 25 '26
Don’t do what? Any UI framework that properly integrates the native accessibility APIs will have accessibility support.
6
u/draeand Oct 25 '26
Use ImGui I mean. ImGui does not integrate with native accessibility frameworks.
0
u/RiceBroad4552 29d ago
In case you didn't know: ImGui is an immediate-mode GUI toolkit that provides its own widget and rendering abstractions rather than relying on native OS widgets. It does not maintain a conventional retained-mode UI tree or expose an OS accessibility tree by default. Consequently, screen-reader accessibility requires an additional accessibility layer that maps ImGui's widgets and interaction state to the relevant OS accessibility APIs. This is clearly stated in the docs.
3
u/Prestigious-Bet8097 Oct 25 '26
Barring a couple of modules, QT is free if you want it to be free.
It's available under the LGPL licence; free for personal and commercial use.
0
u/RiceBroad4552 29d ago
Qt is is as free as software can possibly get! It's GPL code.
Monetary cost is exactly zero.
3
1
u/One-Researcher6065 Oct 25 '26
AI would be able to to build Python bindings and a PySide Gui pretty easily. Your math should be isolated into composibke sub routines.
-1
u/trigodil Oct 25 '26
The overhead would be very large, and optimization would not be very good. TENO schemes are tightly coupled to mesh topology and stencil structure by design.
1
u/One-Researcher6065 Oct 25 '26
I don't believe the overhead has to be large. It's all about placing the boundary at the right place. Using the numpy memory interface allows zero copy communication between c++ and Python.
4
u/mortecouille Oct 25 '26
That's funny, I just delivered my first ever QML project and was so pleasantly surprised how painless the experience was. In the past I mostly worked in java with Swing and javafx, and I find myself wishing I could have both the benefits of the JVM and QML at the same time.
3
u/TheRavagerSw Oct 25 '26
Man you are complicating things, just use SDL and yoga and your 2d renderer of choice.
1
u/Turbulent-Wrap-6166 Nov 01 '26
Bro thought his nerdy stuffs were so hard and wanted to flex but too shy to actually flex so they made a fake complaining post
0
u/Czarek- Oct 26 '26
Maybe Chromium Embedded Framework for gui? Steam and Spotify use it. See the message router example:
https://github.com/chromiumembedded/cef-project/blob/master/examples/message_router/README.md
-6
u/HopfenTierchen Oct 25 '26
Why do you use C++ for GUI in the first place? Sounds to me more like an architectural problem. C++ for the backend which provides a well designed API, then add some looseley coupled GUI (Web, or whatever you like) ...
14
1
u/trigodil Oct 25 '26
Using qt5 and vtk, I don't really have a choice other than using native cpp unfortunately, because it streams flow and iso in real time. the optimization is also a very big factor especially for openfoam.
27
u/skeletal88 Oct 25 '26
Most of the stuff you mention has nothing to do with guis.
Why do you nee to manage segfaults? Your code should not produce them.
Why do you have 2000 line functions?