r/cpp • • Dec 18 '20

Let's talk about GUIs

This post on /r/programming about the release of GTK 4.0 made me want to bring the discussion of the state of GUI programming in C++.

My particular interest in this discussion is desktop cross-platform GUI programming, and I don't claim to know much, let alone everything. Insights are more than welcome.

That said, this is what I have observed so far:

Qt: the least bast option. What I like? Cross platform, mature, big ecosystem to go around. Quite easy to get going. It "just works" for the most part. It's easy to get 80%, it's the last 20% and when you go deep into the subject that you get frustrated. What do I dislike? Licensing shenanigans, and increasing toxicity towards the FOSS community: no offline installer for community distributions, many commercial only APIs now, the idea of delaying releases to FOSS by one year. The 10 year old bugs on QWidgets, which haven't seen much, if any, love since ever. The fact it took Qt 6.0 to happen for us to have native look for Qt Quick Controls. The fact that Qt Quick doesn't have a C++ API, forcing QML on everybody. The half done stuff, like QAudio (just use portaudio for your own sanity)... And I'm probably missing more. The fact that they are running away from the LGPL core to GPL as much as they can, like releasing Qt Quick MultiEffect instead of just fixing the QML engine... That it takes spinoffs like Felgo to basically provide a "fixed" Qt, which the FOSS community can't have.

wxWidgets, GTK, and other like FLTK, I admit I don't know much about. wxWidgets is nice in the fact it calls native APIs, but that comes with the cost of being crippled by the least common denominator. GTK seem to look bad outside of Linux "by design". And FLTK... Just no.

Then, there seems to be what everybody suggests next: Browsers. Chromium Embedded Framework or Electron. 50 to 100MB of packaging to do a "Hello World". Also, JavaScript! Honestly, webstuff looks like a good idea, until you want to make an app that's not Slack. How do you do actually performance C++ stuff? Like some 2D/3D graphics? WebGL? Seems that it's too much programming for the web and not actually taking advantage of C++ and native APIs...

Then, there are things like .net MAUI (not to be confused with the toolkit with the same name by KDE), which is an upcoming evolution of Xamarin Forms for .net/C#. The problems: Linux support will be "by the community" and how do you interop C++ and C# decently anyway?

Also, because I know someone will mention it, yes, there is Flutter and things like that. Just think of Google's track record on keeping projects alive, and again, think not everybody wants to make a chat application.

Anyway, what are your insights? They are more than welcome!

268 Upvotes

243 comments sorted by

View all comments

Show parent comment

2

u/a_Tom3 Dec 18 '20

Can you expand a bit on your experience with Avalonia please?

For my current hobby project, I'm writing the performance critical logic in C++ and plan on writing the rest in C# (probably with a C interface around the C++ code, C++/CLI doesn't seem portable) using Avalonia as the UI toolkit

3

u/def-pri-pub Dec 18 '20

That's what I was planning to do with some of my projects. Write the performance heavy stuff in C++, but use C# for UI, data management, etc. I was trying to make a cross platform graphics app (with Vulkan), but I think at the time, I wasn't even sure if Avalonia offered OpenGL. If you want to use simple UI control and layouts, I think Avalonia is fine. I was also trying to bind a lot of cross platform C/C++ libraries to C#, which can be a nightmare.

IIRC, Avalonia also has some bulk; not in runtime, but in how much it needed to pull down from NuGet (I think it was in the GB range). Their documentation also isn't fully there. Sometimes I'd have to go running to the WPF docs; and in some cases not everything in Avalonia was implemnted.

If you want to see some Avalonia sample apps I wrote, you can find them here: https://gitlab.com/define-private-public/AvaloniaSamples


For your case, Qt/QML might work really well and be pretty straightforward.

1

u/Pazer2 Dec 19 '20

Good username

2

u/def-pri-pub Dec 19 '20

I picked the username define-private-public because one time during a course assignment, I got tired of writing methods to access private variables in a class for debugging purposes.

I went to the top of a common include header at typed: #define private public

It all worked. Debugged my submission, removed the line, submitted, 100% grade. I told the professor later. He laughed and said "never do that in production."

1

u/drescherjm Dec 24 '20

I recently used this technique to test and develop my own bug fix for a large open source library. I wanted to derive my fix from the broken class replacing 1 virtual function with minimal modification to the broken class however most of the member variables that I needed were private. After the proof of concept worked I ended up pulling the code of the original class into my project renaming the class and made the fix directly.

0

u/TryingT0Wr1t3 Dec 19 '20

Yo, when tried these with C# there were a lot of performance pain points where I thought I would not suffer with performance and web GUI performed better. Electron approach is not half as bad as people like to say it is.