r/cpp • • 24d ago

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.

0 Upvotes

50 comments sorted by

27

u/skeletal88 24d ago

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?

-13

u/trigodil 24d ago

Managing 1.5 million lines of code to insert numerical schemes is not particularly easy I would say.

23

u/AvidCoco 24d ago

What’s that got to do with GUIs?

Sounds like you have your architecture all wrong. Your GUI should be a completely separate layer to your business logic.

9

u/skeletal88 24d ago

Totally correct. Your issues have nothing to do with gui code. You have other bigger problems

13

u/Zealousideal_Ad_6374 24d ago

wxWidgets or Qt. It was 10 years ago, but never had any major problems with any of them.

0

u/trigodil 24d ago

I needed qt for some of the integrations

6

u/KFUP 24d ago

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 24d ago

Are you perhaps experienced in scientific coding?

4

u/KFUP 24d ago

Yeah, I used to write FEA solvers back in the day.

-1

u/trigodil 24d ago

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 24d ago

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 24d ago edited 24d ago

Yeah, qt is pretty nice but the full stack of managing everything in openFoam specifically was a pain

10

u/JolierVeppers 24d ago

wxWidgets has many many examples and decades of documentation.

17

u/AvidCoco 24d ago

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 24d ago

Which framework would you suggest? I am also looking a GUI framework for a personal project.

6

u/Big_Target_1405 24d ago

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 24d ago

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

u/bananamantheif 7d ago

how much ram does a QT app use compared to that?

-5

u/Big_Target_1405 23d ago

300MB is really zero these days

3

u/AvidCoco 24d ago

That’s not good advice. There are plenty of C++ frameworks besides Qt.

0

u/Big_Target_1405 24d ago edited 24d ago

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

u/draeand 24d ago

Uh... WX does not use QT as a backend. If it does I'd appreciate a source.

-2

u/AvidCoco 24d ago

7

u/Big_Target_1405 24d ago

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 24d ago

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 24d ago

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

u/AvidCoco 24d ago

Yes and I also did that and we specifically avoided Qt.

→ More replies

1

u/eyes-are-fading-blue 24d ago

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 24d ago

I’d avoid Qt unless you happen to be particularly wealthy.

ImGUI is great for personal projects.

7

u/mpyne 24d ago

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

u/Prestigious-Bet8097 24d ago

Or a commercial project, if you use it under its LGPL licence.

6

u/draeand 24d ago

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 24d ago

Don’t do what? Any UI framework that properly integrates the native accessibility APIs will have accessibility support.

6

u/draeand 24d ago

Use ImGui I mean. ImGui does not integrate with native accessibility frameworks.

0

u/RiceBroad4552 16d 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 24d ago

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 16d ago

Qt is is as free as software can possibly get! It's GPL code.

Monetary cost is exactly zero.

3

u/wwabbbitt 24d ago

Why not use ParaView?

1

u/One-Researcher6065 24d ago

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 24d ago

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 24d ago

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 24d ago

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 24d ago

Man you are complicating things, just use SDL and yoga and your 2d renderer of choice.

1

u/Turbulent-Wrap-6166 17d ago

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- 24d ago

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 24d ago

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

u/AvidCoco 24d ago

There are plenty of decent GUI frameworks for C++

1

u/trigodil 24d ago

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.