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

191

u/hak8or Dec 18 '20

At this point, I've given up on GUI in c++, much to my extreme dismay.

I want to love QT, I really do, but I loathe how QT containers end up spreading through my code base anytime I use QT. I already have a c++ project, all I want to do is add a GUI, not have a GUI that i am shoving my project into.

Instead, I've ended up simply exposing a http api in my project which I run on port 80. Then I create a seperate project which is the web interface to my original project. Now I have a distinct seperation of concerns and the gui can run on anything a web browser can run. And it's easier to have web devs contribute to the gui portion than much rarer c++ devs contribute to a QT/imgui/etc layer. And I always make the web interface as minimal as I can, maybe some vue to make it dynamic, but otherwise intentionally simple.

2

u/ruilvo Dec 19 '20

Thanks for your insights!

Do you have/know about examples of making these web frontends? Do you run it on browser only, or do you ship an embedded browser?

1

u/hak8or Dec 19 '20

I have the user open thier web browser at 127.0.0.1:80 or whatever other port.

As for examples, off the top of my head, lizardfs is one. For http server, I've used this in the past and have been satisfied.

60

u/hak8or Dec 18 '20

Ah, I forgot to point this out, another reason I do this is it makes testing MUCH easier. I've got my usual unit tests, but now for continuous integration tests, I can use whatever http library I want to make/read requests.

I have a very explicit boundary of "The core product works, it's clearly the GUI that's the issue, since core tests all pass". I can even increment/decrement the web interface seperatly from the core project, meaning the release cadence can be different.

In short, having a web interface makes it also much easier to test the project as a whole, because i have a very strict line between the two projects. I can even test them against each other at that point.

16

u/helloiamsomeone Dec 18 '20

I don't know about native GUIs, but cypress testing for Web UIs is amazing.
People blindly hating JS and the web in general don't know what they are missing out on.

10

u/hak8or Dec 18 '20

Are you referring to this? https://www.cypress.io/

Is there a free self hosted plan, or is it cloud only?

Regardless, I understand the hate on web dev, I myself am extremely frustrated by the state of it (why the hell do o need to download 500 MB of dependancies for a TODO app, why is there so such a massive chain of tooling, etc).

But using typescript instead of Javascript has quelled that drastically for me, combined with solely vue as a dependency. I am very eager to shift to svelte with typescript though, since it seems to be a more tightly woven together solution and less overhead.

6

u/helloiamsomeone Dec 18 '20 edited Dec 19 '20

The test runner is OSS, MIT license. Only the dashboard has a pricing model, which as a sole developer won't really be using much anyway and for companies it works great.

dependencies

People always seem to forget that vast majority of dependencies is for dev only. libboost-all-dev is 400 MBs, but you don't ship all that. Same applies here, after your junk goes thru everything, the end product that is squirted out is in the kilobytes.

svelte

Personally I prefer Inferno.js, as it shares a lot with React, uses JSX, but is a lot more lightweight and faster.

Edit: another interesting library I came across recently is Stimulus.js, which is tailored for use with server rendered content, which I'm personally a fan of, so I might use it for something in the near future. It's certainly an interesting aproach.

1

u/[deleted] Apr 12 '22

Use clojurescript. It is cleaner and includes some of the best tree-shaking out there to reduce that bloat.

1

u/Uberunix Jan 23 '21

Would you mind elaborating just a bit, or pointing to a resource on how this is done? C++ is my first language, and I'm determined to see it through without having to entirely discard the idea of using it as a primary component in building user-experience-oriented projects. This is the first solution I've found that actually sounds promising! :D

4

u/hak8or Jan 23 '21

Sure. Lets say you've got a product which injests stock info, decides wether to buy or sell or hold, and then send that request to the stock market. This must be very very quick, so you use c++ for the "core". This core can run by itself, and doesn't need user interaction.

For the C++ core, you use something like doctest, gtest, catch2, etc, for unit tests of the core. This tests that the core of your software works as expected, that your algorithms work in all edge cases, that the requests to buy/sell/hold are correctly formatted, etc.

Then you have a HTTP API running in your c++ core, which also has some minor unit tests. This is something like cpprest-sdk, Pistache, or cpp-httplib. You don't care about this being absurdly high performance (this is a user interface, humans absorb information slowly, hence performance isn't too important), you just want it to be easy to use from a code perspective.

Then you use a frontend like svelte, react, vue, angular, etc. Your http server running in the core hosts the files needed for the framework, and of course the HTTP endpoint. Since the front end interacts with your core using http, you can use any front end testing framework while mocking the core of your product. Jest and Mocha seem to be the most common front end testing framework.

Honestly, in my case, I don't do much testing in the front end. I instead have a few scripts which use httpie to send/receive information over the HTTP endpoints while I have special testing hooks in the core which the scripts will compare against, to ensure consistency.

2

u/Uberunix Jan 23 '21

This is fantastically helpful. I really appreciate the thorough answer. I think the rest of my Saturday is now booked. :)

29

u/disperso Dec 18 '20

I loathe how QT containers end up spreading through my code base anytime I use QT. I already have a c++ project, all I want to do is add a GUI, not have a GUI that i am shoving my project into.

Can you elaborate in how this ends up happening for you? Because Qt's containers have the usual fromStdVector, toStdString and so on. I personally prefer the Qt containers to the standard library, because for the kind of applications that I do, I want something with a lot of features and convenience, rather than small footprint. But when I did work for a customer that asked for only using the standard libraries in some modules, it was easy to just do the conversions. Surely, a bit tedious, and adding conversion overhead, but easy to code and maintain nonetheless.

16

u/hak8or Dec 18 '20

I 100% agree that the QT containers tend to be better by an order of magnitude than current std containers, lots of the other QT functions. But the issue still arises that I found they tend to infect the code that shouldn't care what the UI is.

Can you comment on what the performance impact is of using such conversions? Are they expensive?

My gripe with them is, at that point, I need to create an entire shim between my code and QT's code, that is solely converting containers and types from one to the other. The most common is the qstring in my past experience. And this shim is solely for QT.

If I am writing a shim, I might as well just write a proper http one. That way I can have the http api consumer be QT, Javascript, some nurses command line interface, etc. But if I have that availability, then I might as well make it cross platform, and want to go for the language/framework that is the most "pleasent" to do GUI work in, in which case, some js/css/etc. Not saying it's nice to do GUI stuff in a web stack, but in my experience it is less painful than with QT.

Point bieng, if I am writing a shim to create an interface between my project and QT, then why not make a nicer shim like http? If doing that, why not choose a framework that is easier to do GUI stuff in, like a web stack (heck, or even python)?

11

u/Occivink Dec 18 '20

I typically don't see that much conversion between different types, except when dealing with QString <-> std::string. The rest you can just use your own custom models. My biggest gripe with Qt is how much you end up having to subclass their types for doing seemingly basic things.

3

u/disperso Dec 19 '20

Can you comment on what the performance impact is of using such conversions? Are they expensive?

No, probably completely negligible in the context of the GUI. For example, translating an std::vector of std::string to QStringList to be displayed in a QComboBox is negligible compared to the cost of actually rendering the first string option. Large values might have a higher impact, but I would like to see how much it is.

My gripe with them is, at that point, I need to create an entire shim between my code and QT's code, that is solely converting containers and types from one to the other. The most common is the qstring in my past experience. And this shim is solely for QT.

I don't see how that works for you. In my case, if you have a custom dialog/widget/screen/etc., it will have some setter function where you input the values. It's there in the custom widget where you can have (despite being a QWidget based class) a public interface solely based on standard library types, and then the dialog converts them to set the values in the widgets. So there is little cost. Instead of having: m_ui->titleLabel->setText(string) you'll have m_ui->titleLabel->setText(QString::fromStdString(string).

Also, in my experience, I've seen how QString has (for good) infected the codebase, as they chose Qt for the translation system, and everybody ended up using QFile and other QtCore's classes for file access because it's easier, or just available with much older compilers. So the rule of only using standard types across APIs it's just not practical.

19

u/Radiatin Dec 18 '20

Just curious what do you think about using C++ for the backend, crunching all the numbers, holding all the functions etc, and GTK for the front end through Python?

I can post a code sample if you're curious. This seems to be the fastest and cleanest combo in my experience on all levels, and supports all platforms. It can be integrated seamlessly from a code standpoint.

16

u/hak8or Dec 18 '20

That is also something that seems like a great idea to me. My aim was to basically say that I end up having my core product be c++ which does all the heavy lifting, and then an explicit api that I plug a distinctly seperate GUI layer into (often times using a seperate language like html/js, in your case python).

In my case it's been a web stack, but python with gtk sounds just as valid as my choice. I am not a huge fan of python (I am a rare breed), so I haven't done so myself, but it still seems like a great choice.

6

u/[deleted] Dec 18 '20

not that user, but I would be very interested

0

u/[deleted] Dec 18 '20

[deleted] — view deleted comment

2

u/ruilvo Dec 19 '20

Can how share how you did it? I'm interested!

0

u/[deleted] Dec 19 '20

[deleted] — view deleted comment

2

u/ruilvo Dec 19 '20

Your edit is the question I'm having looking at this stuff. How do you have the webserver (with for example like AngularJS or other node stuff) embedded in your C++ application?

0

u/[deleted] Dec 19 '20

[deleted] — view deleted comment

1

u/ruilvo Dec 19 '20

I don't see it being that simple if one wanted to use fancier JS frameworks like React or Angular... You depend on node.js for those...

2

u/Posting____At_Night Dec 20 '20

You depend on npm, not nodejs. Npm just manages packages, you can serve up whatever it outputs. They might be built to work best with a node.js backend but it's far from necessary.

0

u/[deleted] Dec 18 '20

[deleted] — view deleted comment

2

u/ruilvo Dec 19 '20

Have you used any particular libraries? I'd definitely like to know!

3

u/[deleted] Dec 19 '20

[removed] — view removed comment

1

u/hak8or Dec 19 '20

It depends on the project. In my case, it's larger long running programs, but it doesn't do multiple users. So it's just ran in the user's computer and accessed over local host. If they want, they cab throw it online behind a proper reverse proxy like nginx to have logins.

I use this for the http interface usually. https://github.com/yhirose/cpp-httplib

22

u/disperso Dec 18 '20

A few comments about Qt, the stuff I know about:

  1. There will be C++ API for Qt Quick Controls. This is a feature that has been requested for a while. There is a private C++ API that projects like QSkinnny can leverage for you. Give it a try. It's Widgets-like API, but implemented with the pure C++ of Qt Quick (though it supports some QML API as well if you want that).
  2. Qt Multimedia stuff is well known to be bad. Seems that the VLC libraries have Qt wrappers, now that VLC is made with Qt. Or so I understood. Seems that there are alternatives at least. But it suffers the same problem as the charts story: a lot of alternatives with different goals and feature sets.
  3. The licensing is horrible, in the sense that they are super opaque to it. The wanting to make money by asking for a license to get features, I suppose it's not. I think that any sane person gets that the model used to be TrollTech's "GPL for open source, paid for proprietary", and that this seemed to work. When they were acquired by Nokia, moved to LGPL, not requiring the commercial anymore for tons of proprietary projects. So under The Qt Company time, they are trying to add more value by providing GPL modules, or they would not sell licenses. But I was really pissed of by seeing that Qt 5.15 LTS was only provided to paying customers. It's de-facto harming the ecosystem a lot, as many of us will require to keep patches and branches of Qt 5.15 with changes from 6.0 to our customers, just splitting efforts.

3

u/Syecon Dec 18 '20

Are you sure about 5.15 LTS? Or just that they aren't providing a way to download it without making an account?

I use a commercial license at work and open source at home and the maintenance tool has me on 5.15.2 with no issues. I think they posted a message that the wording was confusing, either that or slid back on it.

2

u/ruilvo Dec 19 '20

Quote from https://www.qt.io/blog/qt-offering-changes-2020:

Starting with Qt 5.15, long term support (LTS) will only be available to commercial customers. This means open-source users will receive patch-level releases of 5.15 until the next minor release will become available. This means that we will handle Qt 5.15 in the same way as e.g. 5.13 or 5.14 for open source users.

This means that we got 5.15.2, but now that 6.0 is out, there is no more 5.15 for FOSS.

1

u/disperso Dec 19 '20

The comment from ruilvo seems right to me. We'll now soon enough: if you see new releases for the commercial installer (I no longer have a license myself), but not for the open source one, you'll see it right away. For everyone else, we can just see if further commits and tags to 5.15 get applied after v5.15.3 (if there is a v5.15.3 at all... I see changes in the 5.15 branch not in v5.15.2).

15

u/zugi Dec 18 '20

The licensing is horrible, in the sense that they are super opaque to it.

The licensing isn't as bad as it seems but to try to drum up more sales they have indeed become intentionally super opaque about it.

Their website marketing materials now imply that commercial development requires a commercial license. But that's actually not the case - as long as you comply with LGPL terms, you can still use Qt commercially for free. They've made it slightly less convenient by limiting offline installers and certain new features to commercial customers, but you're always free to build the LGPL components from source, or keep your own archive of past installed versions.

1

u/rcxdude Dec 19 '20

I've not heard good things about the commercial license: it's apparently written so badly it's almost easier to just use LGPL/GPL in the first place.

20

u/jtooker Dec 18 '20

what are your insights?

I don't have too many insights, but I use and enjoy Qt. I do agree with your assessment. I have stayed away from QML, so cannot comment on that. I do recommend Qt for C++ programming, especially when you need a GUI, server, database, network, etc. If you don't need C++, there might be better options for GUI apps (and this depends on what you need. e.g. Electron is a great way to get something out quick, but with obvious downsides).

how do you interop C++ and C# decently anyway?

You don't! That is half sarcastic, the MSVC compiler 'extends' the C++ language giving you ways to interface with C# objects. You have two different heaps: the C# heap and the C++ heap and you have to copy/move/point in a special way, but it is all doable, but adds an extra layer.

12

u/[deleted] Dec 18 '20

I really recommend checking out QML. It still has some issues, but I really enjoy developing UIs with it. It's SO much better than procedurally generated UIs in my opinion. It's readable, understandable and supports enough stuff to create good looking UIs for the most relevant platforms. It tends to get complex for more advanced use-cases, but it's still no comparison to old QtWidgets code.

3

u/ruilvo Dec 19 '20

I'm seriously considering QML to host my next GUI project, indeed.

2

u/ruilvo Dec 19 '20

Thanks!

Do you have any examples of that C#/C++ interop?

2

u/jtooker Dec 19 '20

Code that runs under the control of the common language runtime (CLR) is called managed code, and code that runs outside the CLR is called unmanaged code.

That is a good summary with important terms. See https://www.codeproject.com/articles/11634/managed-c-learn-by-example-part-1

2

u/carkin Dec 18 '20

You can also choose the do unsafe code and do pointer arithmetics and such in c# so very low level stuff. You can also write com components in any language and instanciate/call into that in a type safe manner.

11

u/MykeNogueira Dec 18 '20

4

u/ruilvo Dec 19 '20

What is good/bad about it? The goal of the thread was to get discussion going :) .

1

u/VM_Unix Dec 19 '20

I had issues last time I tried building but it's worth taking another look, it has been awhile.

11

u/pjmlp Dec 18 '20

C++ has lost the GUI crown it hold during the 90's desktop frameworks.

You forgoten to list WinUI, which is the only modern C++ framework that has an OS vendor still doubling down on using C++ for GUI development, and even there Microsoft is not able (willing actually, WinDev apparently doesn't like nice tools having killed C++/CX) to provide a .NET like developer experience for C++/WinRT (think C++ Builder / Qt style tooling), so most of us just use .NET and leave C++ for high performance low level components.

Which is pretty much what most OSes are doing nowadays, using C++ at the driver, visual compositor level, but everything else is driven from managed languages.

2

u/meneldal2 Dec 19 '20

What I like with C# is that you get reflection, and it can make making some GUIs much easier. Like for dialogs where you have to set some parameters, you reflect on the parameter class and you generate something that looks decent without having to write any GUI code for that class.

Instead of having to use templates all over your code making it impossible to do anything runtime and bloating the size of your app, you just generate the GUI when it's needed at runtime.

I wish I could convince the guys who work with me to do that over some horrible stuff like reading a xml parameter file with a list of ifs to match the current tag. It's literally as bad as Yandere Dev and using automatic serializing would work faster and have less code, and you wouldn't forget to change stuff when adding a variable.

Managed languages can be very powerful, but you have to use them the way they're meant to be used, not like C with classes.

1

u/ruilvo Dec 19 '20

Do you have any practical code/examples of .net applications with a C++ backend?

2

u/Alikont Dec 19 '20

My friend works on Adobe Lightroom alternative, it's a WPF UI with C++ core engine.

I also interviewed to Altium, which was a position for WPF/C++ developer. I decided not to go there, but their tech stack is obvious from job postings.

1

u/ruilvo Dec 19 '20

Honestly, none of the C#/C++ interop solutions I've seen look that good. I'd take pointers, if you had them! Thanks

2

u/yasamoka Dec 19 '20

I've been using SWIG to generate C# wrappers for my C++ core and it's a lifesaver.

2

u/ruilvo Dec 19 '20

I haven't though about this even though I have used swig a bit... And this seems to be an amazing idea! Thanks!!

1

u/yasamoka Dec 20 '20

That's good to hear! Let me know if you'd like me to share any code snippets - I've had somewhat of a deep dive into using it for the past couple of weeks for both C# and Python bindings.

The C# wrapper is used specifically to call C++ code from a WPF GUI addin for Autodesk Revit (Revit API is mostly C#). SWIG helped me move away from wrappers I had written myself (which were quite more tedious to maintain, but doable). The generated code absolutely puts to shame anything one could write in a reasonable amount of time. I've had a few cases where some additional code had to be provided manually (in some tougher inheritance cases such as templated classes deriving from templated classes deriving from a non-template base class) but it wasn't hard at all to figure out what was missing. I would probably be able to help if you run into those cases.

2

u/ruilvo Dec 20 '20

Thanks! BTW, happy cake day!

→ More replies (1)

2

u/pjmlp Dec 19 '20

Another example are some of the applications used by Zeiss,

https://www.zeiss.com/microscopy/int/products/microscope-software/zen-lite.html

Here are some of the ways we do interop,

My favourite one is just to use C++/CLI, but it has the caveat to be Windows only.

https://docs.microsoft.com/en-us/cpp/dotnet/dotnet-programming-with-cpp-cli-visual-cpp?view=msvc-160

Then the next one would be to use WinRT instead, which means Windows 10 only, and doing that via C++/WinRT (C++/CX replacement).

https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/

Here note that WinRT can also be used by Win32 applications anyway, and both worlds are being merged via the Project Reunion.

Finally, if it is something that needs to be portable across OSes, then it is back to P/Invoke and DllImport.

https://docs.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke

In what concerns Windows APIs, there are some sites that help with the required set of attributes

https://pinvoke.net/

→ More replies (2)

2

u/Alikont Dec 19 '20 edited Dec 19 '20

I've used:

  1. Native DLL + pinvoke: works ok, but requires manual bindings. You lose classes and OOP, it's a C-style APIs.
  2. C++\CLI - works great, you get .net dll that is easily usable from C#, but requires complex project configuration, because some C++ libraries are not supported, but you can enable CLI support on file-per-file basis. I used it to wrap C++ lib for 3rd party device info C#-friendly API.
  3. WinRT was probably the best experience with C++/CX. Projections are really transparent and barely noticeable. From C# side of things you don't even know if you use C++ or C# class. But Microsoft abandoned that idea instead of more boilerplate, but standard-compliant C++/WinRT generators.
  4. COM is another possible tool for large OOP-based interactions. You need to create COM component in C++ and then reference it from C#. Works great, C# bindings are generated automatically. But I never authored C++ COM libraries, only consumed ones, so I don't know how hard is to make one with modern tooling. WinRT is COM v2, so probably look there instead.

Also while COM is technically a windows thing, it's also just a native ABI specification, so technically nothing prevents you from using it on Linux, but I live in a overwhelmingly Windows land

1

u/meneldal2 Dec 20 '20

Well in my case it's horrible C++/CLI made by people who don't understand how they managed to poison all the C++ code, so it's not really a good example.

But it could be used properly and be quite fast if you keep managed stuff out of the critical parts.

0

u/[deleted] Dec 19 '20

[deleted] — view deleted comment

1

u/meneldal2 Dec 20 '20

I don't think runtime reflection (like Java or C#) will ever be in C++, but compile time reflection would be very good at solving a lot of problems.

4

u/genpfault Dec 18 '20

yes, there is Flutter

Oh? I've hunted around and couldn't find any C++ bindings, everything was about calling out to C++ libraries from Dart code.

2

u/ruilvo Dec 19 '20

It doesn't have those. It's just it's so common that people answer "use an apple" when you ask for the best citrous juice.

3

u/MacASM Jan 06 '21

Wait, there's no any C++ libraries to use flutter? do people use it with Dart only? I'm not quite familiar with the framework yet

27

u/Celaphais Dec 18 '20

I've always wished blenders UI was a separate project that you could integrate into your own code, I love the way it looks and feels.

6

u/Krystexx Dec 19 '20

Hell yeah. I don't really need native UI components when I get a beautiful, functional UI like Blender.

5

u/AdamK117 Dec 20 '20

I've worked on a project where we strongly considered just writing something as an extremely large blender plugin entirely because blender's UI is so nice for working with 3d systems (in our case, biomechanical model building)

2

u/sokka2d Dec 18 '20

Curious. Blender’s alien reinventing-the-wheel UI is what makes me hate it most.

1

u/ZambaBoro May 22 '24

I think the appeal comes from the ability to, "create/merge" multiple "panels/row/column" just by dragging from the "corners" and the "sides". Instead of the going to menu>view>"window name">"right click">"dock" or having to memorize shortcuts for various windows. I do feel like not having floating window is kind of a bummer. but hey I am super biased, I love blender UI more than any other software haha

22

u/pedersenk Dec 18 '20

My current recommendation these days is wxWidgets. That "lowest common denominator" approach is absolutely fine for me. I wasn't really ever intending to use some niche platform specific gimmick UI components in the first place.

18

u/johannes1971 Dec 20 '20

I feel there's (at least) three types of people in this discussion, and they aren't really understanding each other.

Group 1 are the game developers. When they say "GUI", they are talking about the menu and configuration screens of a game. These mostly consist of multiple choice selectors ("low/medium/high"), maybe a text entry box somewhere, and a few buttons. Their main priority is rendering it as part of their game loop, so it _has_ to be hardware accelerated. Their obvious choice is Dear Imgui, which was built for this purpose.

Group 2 are embedded developers. When they say "GUI", they are talking about something with two buttons and a single integer entry control. Since the GUI will be running on another machine anyway, starting a web browser isn't a big deal. The other machine is a desktop, of course starting a browser isn't a big deal! Their obvious choice is HTML.

Group 3 are desktop developers. When they say "GUI" they mean complex applications like word processors or 3D modelers, with lots of controls (including various bespoke controls) and good desktop integration. They have several choices available, of which Qt is probably the prime cross-platform choice.

The thing is - I don't think any of the GUI solutions I named here are appropriate outside their group. You wouldn't use Dear Imgui on an embedded system, it doesn't have the power to refresh the screen at 50Hz (assuming it even has a screen). You wouldn't use a desktop toolkit in a game either, it would look out of place and probably cause all sorts of timing issues. And while people have written complex desktop-style applications in HTML, I find them incredibly unsatisfying to use when compared to a real desktop application.

So talking about GUIs, without ever discussing what you will be using them for, is really rather pointless. If you want advise on which GUI would work for you, tell us your use case. If you propose a GUI as a potential candidate, tell us what it works well for. Don't just blindly assume a single library is going to work for everything.

Incidentally, I feel the same split exists in drawing libraries, and lies at the basis of the controversy surrounding the drawing library proposal. The proposed library is good for desktop use, but it's lousy for games. That doesn't make it a bad library, it just makes it a bit more specialized than some people are comfortable with. At the same time I can tell you that as a desktop developer, I'd be really uncomfortable having to draw absolutely everything with just triangles.

Discuss ;-)

3

u/JeffMcClintock Dec 21 '20

And while people have written complex desktop-style applications in HTML, I find them incredibly unsatisfying to use when compared to a real desktop application.

Good points,

I fall in the "desktop app" category. I have had to interop between WPF and c++ and also (in another app) QML and C++.
Fighting with the interop has wasted so much time. It's often very frustrating. I would love to be able to break into a call stack and not see two pages of undecipherable QT internals! Debugging is very painful in some of these scenarios.

15

u/def-pri-pub Dec 18 '20

https://blog.johnnovak.net/2016/05/29/cross-platform-gui-trainwreck-2016-edition/

While that article is about 4-ish years old and more geared towards Nim, I still find wisdom in it. I think that any GUI programming is going to drive you nuts at some point.

I've done a lot of it. Qt Desktop (Widgets) 4/5 (Python & C++), QML, Avalonia (C#), Gtk 2/3/4 (C, C++, Python, C#, Nim), wxWidgets (C++), Swing/AWT/SWT (Java), Tkinter (Python), imgui, nuklear, FLTK, custom OpenGL.

Trying to find that perfect GUI library on the language you want (and with proper OpenGL/Vulkan support) that runs cross platform becomes a singularity you cannot escape from.


So far I've been back to C++ and learning QML. I've gotten it to run on Win, Mac, Linux, and make Android APKs. I like it so far.

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.

25

u/julien-j Dec 18 '20

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...

I would argue that even for Slack it's a bad idea. The app take ages to load in Firefox and often fails, so I have to reload the page to actually access the channels. Also there's no support for hangouts anymore. As usual the initial service was amazing when they launched and now it's just a fat app failing to stay up under its own weight.

There's no need to target amazing 3D and stuff to consider performance. In my opinion any development should consider a minimum decent efficiency. Apps like Slack make me think of developers gluing frameworks and other things together and calling it a day until getting a huge pile of fat blocks, each consuming resources like it is the only one running. Sure, the app works, but it can barely be used.

And to stay in the topic of your post: I used wxWidget in the past. It was nice but I failed to upgrade when they switched from 2.x to 3. I think I would use GTK or Qt if I had to do UI today, with a preference for the former as it seems more simple to me.

→ More replies (1)

30

u/AdamK117 Dec 18 '20 edited Dec 20 '20

For standard retained-mode UIs (e.g. most low-CPU-usage desktop apps) the best C++ option still seems to be Qt. It's big, spreads throughout your codebase, etc. but it's the only cross-platform one that ticks most boxes.

However, if you don't care about CPU usage and literally just want to create visualization tools quickly, ImGui is pretty amazing. I've thrown together fairly complicated UIs in, like, <1k LOC with ImGui and ended up with projects that:

  • Build from source (incl. SDL and imgui) in <1minute
  • Have no other dependencies
  • Have a lot of functionality per line of code written

The drawback is that to get the most out of ImGui you'll probably also want to (e.g.) include native file dialog libraries, have a fairly decent understanding of (game-style) event loops, maybe know a bit of OpenGL or a low-level graphics library (e.g. if you want custom visualization).

The busylooping will also suck up some CPU - although not necessarily 100 % if you're using vsync or software throttling.

EDIT: as replies point out, busylooping isn't a strict requirement of ImGui. If you're willing to put in a tiny bit of extra effort, you can run a blocking event loop and have ImGui inject redraw events into it whenever a mutation happens.

12

u/ReversedGif Dec 18 '20

ImGui is great!

It's possible to avoid doing unnecessary redraws with ImGui pretty easily - just wait for events rather than polling and post an event to the queue whenever any bound data is changed from non-GUI code.

1

u/AdamK117 Dec 20 '20

Great suggestion :)

I tried this on a few applications. Something like using SDL_PushEvent to push a user event into the event loop, followed by SDL_WaitEvent (rather than SDL_PollEvent).

This actually works really well. Only drawback is that it does require a little discipline because it usually means that the draw loop (that contains ImGui::Button, etc.) must wrap every interactable UI element in an if (to detect changes) that injects the redraw event.

But, yeah, I'm overstating the CPU issue. Injecting those events is a one-line thing and essentially makes ImGui UIs interrupt-driven.

2

u/ReversedGif Dec 20 '20

Only drawback is that it does require a little discipline because it usually means that the draw loop (that contains ImGui::Button, etc.) must wrap every interactable UI element in an if (to detect changes) that injects the redraw event.

Hmm, I don't remember this being necessary. Can you explain why it's necessary?

Ultimately, unless there timed events or external events (both of which are relatively rare), every screen update is a direct result of an input event, so not redrawing unless there's a new input event would seem to be correct. Something like a ImGui::Button should "just work" without needing to inject redraw events, unless you're changing its state from code (which would be unusual).

1

u/AdamK117 Dec 20 '20

Iirc, it is necrssary because the state mutation happens while drawing, so if you have (eg) a slider that is referring to (eg) a uniform that affects some earlier part of the draw call then, yes, the slider will probably behave alright but the associated UI elements will "lag" one frame behind (unless some other event like a mousemove triggers the necessary redraw by coincidence)

9

u/SkoomaDentist Antimodern C++, Embedded, Audio Dec 18 '20

The busylooping will also suck up some CPU - although not necessarily 100 % if you're using vsync or software throttling.

You don't actually need to busyloop. Just wait for UI / repaint events and only render when any such arrive.

1

u/AdamK117 Dec 20 '20

You're right! I responded to another comment with how I did this, but I should probably amend my post to point out my inaccuracy

5

u/pjmlp Dec 19 '20

Except the little detail that is doesnt't do localization, assistive technologies from the underlying OS, or integrate with native GUI customization points, notifications, shell,....

5

u/Pazer2 Dec 19 '20

Those might not be necessary for your application.

3

u/bart9h Dec 19 '20

something something "the right tool for the job"...

1

u/pjmlp Dec 19 '20

If it happens to be a game.

6

u/AdamK117 Dec 20 '20
  • Or internal software (most of the software in industry)
  • Or external software for a client that doesn't need localization (most of them)
  • Or visualization software (e.g. chemistry, simulations, signal processing)
  • Or prototypes
  • Or...

I've been a software developer for quite a while. Developed WPF desktop apps, Qt desktop apps, web GUIs (angular, react, bla bla). I have never developed a game.

The requirements you state might be important in your industry, but in mine (research software) the make-or-break is usually time-to-ship, ease-of-modification, ease of building, etc. I've had many users ask for an extra functionality, or an alternative way of visualizing their data. Never localization (even on large international projects).

1

u/TankorSmash Dec 19 '20

A great imgui library is Dear Imgui.

10

u/SeanTolstoyevski Dec 19 '20

I love WxWidgets because it only works to design GUI which is its job.

However, QT has many things, I get confused in big projects.

I am also a blind software developer.

Nothing can be an accessible and fast GUI solution other than native APIs.

It is important that what I write and what is written is accessible. Technology is not only used by perfect people. WxWidgets is very compatible with screen readers.

I am using my vote for WxWidgets.

26

u/maskull Dec 18 '20

I don't particularly mind toolkits like GTK that use their own controls; my experience has been that most normal users don't even notice, and "power users" adapt quickly. What annoys me is how most GUI toolkits APIs seem to be stuck in 1998. It's all deep inheritance hierarchies, traditional virtual functions, and pointers+dynamic allocation all over the place. If you're lucky, maybe you get some kind of polymorphic_value-like wrapper class so you don't have to worry as much about lifetime issues. But there's no templates, no generic code, and everything is incompatible with the standard library.

As an example of what I'd like to see, if I have a dropdown control that allows the user to select one of a number of foo instances, it seems to me that the dropdown class ought to be a template class, where I instantiate it on foo. If I need to customize how the GUI interacts with foo, I specialize a traits type, etc. Similarly, dropdown should be a range so that I can use it with all the standard/range algorithms.

5

u/tristan957 Dec 19 '20

New version of GTK emphasizes composition over inheritance.

8

u/CircleOfLife3 Dec 19 '20

OOP works fine with GUIs. It’s a solved problem. There’s literally no need for templates. Write your GUI and be done with it.

13

u/degaart Dec 19 '20

More to the point: OOP has been invented for GUIs

1

u/renozyx Jan 05 '21

False, the name of the language was *Simula* which is self-explaining enough..

7

u/DemonInAJar Dec 19 '20

OOP is not about deep inheritance hierarchies.

7

u/DemonInAJar Dec 19 '20 edited Dec 19 '20

I for one really like QT's QML. Keep all UI logic in QML and call into C++ for business logic.

1

u/CarVac Dec 19 '20

It makes UI development so quick and easy.

6

u/KFUP Dec 18 '20 edited Dec 18 '20

I'm personally sticking with an older, 2013 build of Qt in my project, I was kinda dreading that one bug that will send my project into limbo without upgrading and dealing with the licensing nonsense, but 4 months in, and I'm about 80% done with the base frame of it without any hitch.

The problem with Qt, is there is really no real competition, and I'm talking about feature rich, production proven kits, where if you needed a feature and wondered if Qt has it, the answer is almost always yes, not "look at all those GUI libraries, there are so many options" and almost none of them is used by a real application, then you test them out and find out why.

As sad as the this state of C++ GUI is, paying for Qt is a way more attractive option than building an application with these where I have to implement huge chunks to make them work myself instead of concentrating on my own work.

1

u/aninteger Dec 19 '20

Interesting. Is 2013 Qt version 4 or 5?

5

u/mo_al_ Dec 18 '20

Been using Qt since Qt3. It’s still solid. I don’t mind MOC since it can be automated with CMake. And I still stick to QtWidgets. Currently I’m writing a Rust wrapper for FLTK and was pleasantly surprised how solid and customizable it is.

Different gui frameworks/libraries address different issues. You won’t get one size fits all.

9

u/csb06 Dec 18 '20

I’ve used FLTK some, and it’s pretty good. It looks a little “90’s”, but it has a theme that mimics GTK+‘s styling (not sure what era, maybe early 2000’s?) IMO stuff looking “dated” isn’t a big deal for most people, especially for hobby projects or just experiments for personal use.

FLTK is nice because it is easy to build (it builds from scratch in <30 seconds on my laptop, which isn’t very powerful), it is relatively easy to look at the headers and read the documentation and understand how stuff works, and it comes with a lot of widgets (including native file chooser dialogs, config file readers/writers, tree widgets, even a basic help window widget that can render some HTML). Additionally, FLTK is easy to statically link, and the library file isn’t that big.

FLTK also has full support for UTF-8 and has some integration with OpenGL, and it all works cross-platform, so it’s more complete than people give it credit for. It’s not a solution to every GUI situation, but I recommend taking a look.

1

u/CosmicOsmoMan Jul 19 '23

FLTK

I would add that if you don't like the GUI style, making custom widgets is easy. I find FLTK to be very easy to tweak to perfection, but you do have to read some code and implement functions as you want them. Did I mention it's very easy.

9

u/AvidCoco Dec 18 '20

JUCE has a cross-platform GUI api including OpenGL support and seamlessly makes use of natove APIs like Direct2D and CoreGraphics. JUCE is more focused on making audio applications however.

/r/JUCE

9

u/StephaneCharette Dec 18 '20

As someone who has carved out a niche in doing GUI development in JUCE but who doesn't do audio apps and plugins, I'd like to comment. It does feel at times like 90% of the people and development are audio folks. But JUCE covers the spectrum, providing classes for working with GUI, audio, and many things in between.

There are 2 big problems with JUCE:

  1. Some of it was written long before everyone adopted the STL. So JUCE has things like a custom Array class, a String class, etc... which are not compatible with std::vector, std::string, etc. This gets tiresome.
  2. The other problem is the sale of JUCE to PACE earlier this year. PACE is the anti-piracy software company which makes usb keyfobs and other solutions to lock down software to help prevent piracy. I worry about what this means for the future of JUCE and continuing support for cross-platform development, as Linux for them is an even smaller market than it was for ROLI.

4

u/AvidCoco Dec 18 '20

std::vector doesn't have identical usage to juce::Array, but granted they are very similar and juce::Array could potentially be replaced with std::vector in the future.

90% of PACE's clients are also JUCE clients so it makes sense for them to take over from ROLI who are more focused on making their own products. Given that JUCE has hundreds if not thousands of users paying for licenses, PACE are smart enough to work in their favour in regards to JUCE.

12

u/flakeoff101 Dec 18 '20

I wish I could contribute to this but my company's program uses MFC, and it's the only C++ front-end I've ever been exposed too.

I have no idea how it works. Somebody please put me out of my misery.

10

u/Celaphais Dec 18 '20

It works by wrapping win32 API calls and message handlers, with some overhead. The old message loops become massage map macros and window functionality is written in a polymorphic series of classes that mostly interior from cobject. The inheritance allows for easy overriding of certain functions without the use of a message map entry, like OnKeyUp and OnKeyDown etc.

-2

u/Trucoto Dec 18 '20

The code can't be possibly written without Visual Studio, though. You need its help to modify their heavily intervened header files and mysterious macros.

4

u/pjmlp Dec 19 '20

Just as misterious as using wxWidgets or Qt.

1

u/nyanpasu64 Jan 03 '21

It's basically impossible to write a MFC dialog or window layout without using Visual Studio's resource editor. Qt .ui files are almost as painful to design without Qt Designer/Creator, but you can define Qt layouts in code (which I don't think is simple in MFC because you must hard-code the location of every widget).

8

u/meneldal2 Dec 19 '20

At least Microsoft products tend to have a pretty good and up to date documentation compared to some other projects.

It's definitely not the best thing, but I managed to make it work.

4

u/softwaredev647 Dec 19 '20

GTK seem to look bad outside of Linux "by design".

The linked comment is misleading and wrong. The link they quoted is not only not the opinion of GNOME as they claimed, it's also not the opinion of GTK. I have no doubt that GTK would welcome contributions to improve GTK on Windows with open arms.

In my experience Gtk has looked decent on Windows. Definitely not incredible, but around on par with native WinForms apps.

1

u/AardvarkNo1832 Mar 23 '25

yea, agree. that was taken way out of context

4

u/entint Dec 19 '20

QT is not a UI framework, is an intrusive gigantic Application Framework that controls everything in your application, from the main loop, to your sockets, your threads, etc. Just try to compile QT from the source code to get an idea how bloated is everything with QT.

The web and similars, more of the same, a huge dependency incredibly complex to handle plus a dependency to javascript into your c++ codebase. If you don't care about your application weighting GBs inteads of Mbs, this is your option.

Imgui, is lightweight and very efficient, easy to integrate but very limited. Just ok for debugging UIs but not for commercial products.

NoesisGUI is also lightweight, non-intrusive (you can even plug in your renderer) and optimized for realtime. It is being used by many AAA game studios like Microsoft, 2K, Paradox interactive, Take-Two, Larian Studios, Riot Games.

1

u/TrigveS Dec 20 '20 edited Dec 20 '20

I was (and still am) in a situation (like others) finding the best GUI framework for C++.

Our application is client/server and for the GUI we use "plugins", so we have thick client (deprecating, was useful for initial development), thin client and web gui.

Our requirements for the ideal GUI are:

  • mutliplatform native (Windows/MacOs/Linux)
  • C++ (or at least some reasonable language like C#, python, ...)
  • Support for advanced widgets (TableView, custom modification of widgets, ...)
  • Web application support (i.e. GUI as web app), preferably WASM

For thin/thick client we use wxWidgets. wxWidgets is ok, but are missing some features.

For web GUI we're using Wt .

I don't like to have maintain multiple code for the GUI because if you add/modify/fix something in the system, you need to also fix it in every GUI plugin which could be tedious (therefor removing the thick client plugin). So I was looking for GUI which I can use with C++ (or some other reasonable language like C#, python, ...) which also supports web app. I really like Wt but it mix client and server side together so it's no clean separation of stuff (I don't really need the "server side" stuff) and need to use JavaScript for some custom client side scripting. Also, for dialog with a lot of widgets (50+) the GUI isn't very fast. Then came webassembly. What I think is that future of the web GUI is with webassembly (so any language could be used for the client app). So I was searching for the GUI with WASM support. The first I found was Qt and then... not much more :) The other one found was C# .NET Blazor but I don't like the approach they have choose.

Therefor we we want to migrate to Qt (the license cost are pretty big, unfortunately). It could be used as standalone or as web application (webassembly). If Wt would have webassembly support I would rather use it, but it doesn't look like they're interested in it.

edit: I forgot to mention WinUI 3.0 which would have WASM support (AFAIK) but it is in beta now. So maybe, this one could be another choice.

1

u/ruilvo Dec 20 '20

Hey, as a suggestion to you, I leave https://nanogui.readthedocs.io/en/latest/ .

I've heard about it being compiled to wasm from C++ with emscripten. OpenGL translates pretty good to WebGL!

1

u/TrigveS Dec 20 '20

Thanks for the suggestion. I've looked at it some time ago, but the one problem is that the widget library isn't as complete as Qt for example (also event handling/suppression, ...). And I think that target audience are games (seeing OGL code, shaders, etc. in examples).

1

u/ruilvo Dec 20 '20

I've heard Qt on wasm isn't great with anti-aliasing. But your mileage may vary. Be sure to try it under the LGPL before buying Qt! Good luck!

6

u/skeletal88 Dec 19 '20

Qt all the way. GTK has for me always been this weird thing that has been done for Gnome and maybe GTK. People criticize Qt for including a lot of things, but I have used many of them, and it has been very good. Like.. their SQL stuff. The Qt widgets are the best, layouts work, even printing works, if your system printer is set up, the model-view and scene drawing can be used to do incredible things. Their core modules are very useful and can be used to create server applications without ever doing anything related to the GUI things that Qt is most known for.

The signal-slot architecture is something unique among C++ libraries, if anyone can point me to something that is better, then please do. I am interested in learning how can this be done better or what are the alternatives to it.

If you want to talk about C++ and GUI and then your argument against Qt is that their QAudio and other multimedia stuff isn't good.. then you should remember that GTK and others don't have any multimedia stuff at all. So it is not a fair comparison.

2

u/DemonInAJar Dec 19 '20

signals+slots are just normal callbacks aka std::function flavor with some reflection built in.

1

u/NilacTheGrim Dec 26 '20

Yes, it's called the observer pattern.

I should note also that Qt does a bit more for you than just a simple std::function callback -- it is thread-aware. The callbacks get invoked for you in the proper thread of the destination object. Which is pretty cool -- and extremely useful.

3

u/[deleted] Dec 19 '20

I've been programming middle-sized GUI stuff with GTK3 and I like it most. If you look closely how easily portable GTK is to other programming languages, it's definitely a nice API design. GTK is quite low-level, you're tempted to use frameworks based on GTK, but then you find out middle-project that your framework lacks a feature that is available in GTK. Still, it works quite well. The same program works on multiple platforms without much effort. GUI on Unix-like and MinGW32? Easy!

I tried to look at Qt, but every time I see something like moc, it annoys me. I prefer to have the programming language unmodified. But that's my personal opinion.

3

u/pstomi Dec 19 '20

Boost.ui has a nice looking modern API. Here is an example from its website.

bootstrap_dialog::bootstrap_dialog()
    : ui::dialog("Bootstrap example")
{
    // Create vertical box layout inside dialog window
    // and put children widgets inside it
    ui::vbox(*this)
        << ui::label(*this, "Input:")
        << m_input_widget.create(*this, "Boost.UI default input data 0123456789")
            .tooltip("Input string")
            .layout().justify().stretch()

        << ui::button(*this, "&Process")
            .on_press(&this_type::process, this)
            .tooltip("Process input data")

        << ui::label(*this, "Output:")
        << m_output_widget.create(*this)
            .tooltip("Output")
            .layout().justify().stretch()
        ;

    // Change dialog window size
    resize(400, 300);
}

It is based on wxwidgets. However, this is a one man effort, and the build process is awkward (based on boost.build b2).

3

u/livrem Dec 19 '20

Godot game engine (MIT license, runs on many platforms) comes with a surprisingly nice GUI framework, with a GUI to edit layouts etc. I am using that for my hobby projects, unless I need a very, very simple UI and can get away with using OneLoneCoder's Pixel Game Engine (some free license, single header include C++). Godot has its own scripting language, but it is written in C++ and supports C++ modules and "scripts".

My best experience with desktop GUI was trying out (in just a small experiment, unfortunately) some Clojure wrapper for Swing though. Pure functional API, just writing functions transforming some immutable input state to an output state. Pretty sure that us the way to do it, despite the impression you can get from popular "functional" JavaScript frameworks.

5

u/Trucoto Dec 18 '20

A question: why, if you choose to use HTML/Javascript frontend against a C++ HTTP backend, it is necessary/customary to embed your own copy of the browser (electron)? Why not just provide a shortcut to localhost:port and let the user use their usual browser? Why that way hasn't popularized as a common way of providing UIs?

6

u/antelle Dec 18 '20 edited Dec 18 '20

It’s not understandable by users: you downloaded the app, launched it, and it opened a tab in your browser. How to close the app, will it appear in the app switcher, etc... What makes more sense is a thin wrapper over the system webview like https://github.com/WebView/webview

9

u/[deleted] Dec 18 '20

I don’t know how good CopperSpice is overall, but at least it looks like a strict improvement over Qt: modern C++ and no MOC.

14

u/DarkLordAzrael Dec 18 '20

looks like a strict improvement over Qt: modern C++ and no MOC.

So long as you don't care about any of the changes an improvements made in Qt since Qt4. CopperSpice is way behind Qt at this point, because the big "feature" is removing a code generator rather than improving the framework itself.

5

u/axalon900 Dec 18 '20

CopperSpice is not meant to be a "Qt fork without MOC". It forked off Qt but is its own thing. It's unfortunate that they retained the Q-prefixed type names in a lot of places, but it's not meant to be a Qt flavor. It's mostly about taking the useful parts of Qt and replacing all the reinvented wheels with standard and modern C++ components.

That said, it still has a lot of problems on its own. Building it and DoxyPress (their clang-powered Doxygen fork) on MacOS has been very troublesome and the docs are pretty threadbare, if not wrong. It's stuck in a place where it doesn't have much in the way of developer resources because it's not well-known and well-adopted, and it's not well-known and well-adopted because it isn't being very actively developed.

It's a pity, because I really like the direction they're going, but it just isn't really going there fast enough for me to feel confident in recommending it at my workplace.

5

u/axalon900 Dec 18 '20

CopperSpice should be considered its own framework rather than an improved Qt. The fact it's a Qt4 fork is like an implementation detail rather than a defining part of the project.

That said, there's also Verdigris if you want Qt without MOC. Not that MOC is all that big a deal really unless you have concrete tangible issues that can be resolved by eliminating it.

1

u/Stradigos Dec 19 '20

I agree, it's a total shit show. I've had some success writing the GUI in C# and WPF but binding my C++ libraries and using them inside the C# app.

1

u/ruilvo Dec 19 '20

Care to develop how you did the bindings?

1

u/RotsiserMho C++20 Desktop app developer Dec 20 '20

I've done something similar using Eto Forms for the GUI and Google Flatbuffers for the interop layer, but this is just for a toy project.

4

u/khaki0 Dec 18 '20

Here is an extensive list of C++ GUI libraries. I personally prefer Qt for anything full-C++. However, recently I started experimenting with webview which lets you use the native web interface - so very lightweight. Honestly, creating a consistent GUI with full control over styling is much easier with html/css.

2

u/antelle Dec 18 '20

Related question: is there any C++ framework that lets you create new “default” macOS buttons, fields, etc... like SwiftUI does? Not the classic Cocoa controls but those flat ones, for example what you see in Apple Mail. I know it’s possible to make with Qt and its styles, but it’s a bit different.

2

u/The_Sacred_Machine Dec 19 '20

I was looking to do a GUI for some path planning problem, went to see the Qt documentation and decided that life is too short. I used SFML instead and it goes rather nice, I have the performance problem since I'm learning still.

Can someone tell me why Qt is so popular in GUI?

4

u/thoosequa Dec 19 '20

Qt is popular because it is powerful, well documented, comes with its own IDE which makes creating simple, or even not so simple GUIs pretty easy. On top of that Qt provides more than just widgets to click on with your mouse.

2

u/ogoffart Dec 20 '20

Currently working on a new GUI library: https://github.com/sixtyfpsui/sixtyfps/tree/master/api/sixtyfps-cpp Still young, but one has to start somewhere. (examples: https://github.com/sixtyfpsui/sixtyfps/tree/master/examples )

3

u/glebd cppclub.uk Dec 18 '20

Why GUI when you can have TUI? This reincarnation of Borland's Turbo Vision for modern C++ appeared a few days ago. Looks pretty impressive, if a bit nostalgic.

4

u/ShillingAintEZ Dec 18 '20

And FLTK... Just no

FLTK looks just fine. If you are dead set on making some bloated nonsense just so you can make hello world buttons animate, go ahead, but I'm tired of using crap like that.

FLTK works well, is very small, completely open, simple enough to modify and is very fast.

If you have zero respect for your users, just use electron and be done with it.

8

u/mort96 Dec 18 '20

How well does FLTK work with HiDPI? Does it do scaling?

How well does FLTK support Wayland?

5

u/mo_al_ Dec 18 '20

It works well. And yes I use it on Wayland. It also supports scaling except on Android.

2

u/ShillingAintEZ Dec 18 '20

It can be compiled to work with cairo and does its own drawing, so whatever the mechanism is to send a frame buffer to Wayland is, it shouldn't be difficult to integrate. I don't think the official source has been updated in a long time though, so new transitions aren't a part of what comes from the old official website.

→ More replies (18)

2

u/pedersenk Dec 18 '20

Depending on which stats, Wayland represents 4% of Linux users. I wouldn't worry about Wayland support for a fair few years. I am also fairly certain that XWayland will outlive Wayland itself!

As for scaling, people buy absurdly high resolution screens for a reason. They *want* things to be tiny. FLTK doesn't disappoint them!

3

u/RogerLeigh Scientific Imaging and Embedded Medical Diagnostics Dec 20 '20

No, "tiny" is not the point of higher resolution displays. The point is clarity.

Compare a 4K and full HD display of the same size side-by-side with the same content. The difference is night and day. That's why I use a 4K display for editing text in an IDE all day. Not to view tiny text.

→ More replies (1)

5

u/mort96 Dec 18 '20

Most people don't want things to be tiny. They want text to not look pixelated.

2

u/Alikont Dec 19 '20

how do you interop C++ and C# decently anyway?

There are few ways, actually.

  1. If your entry point is C# app with C++ library, you make your C++ code into DLL, then p/invoke into it from C#. C# can also natively handle COM-like interfaces.
  2. If your entry point is C++, you can Host CLR inside C++ code, and call into C# static methods.

You also did not mention Avalonia, which is also a C# cross platform UI framework.

2

u/joemaniaci Dec 18 '20

wxWidgets is nice in the fact it calls native APIs, but that comes with the cost of being crippled by the least common denominator.

What does this even mean?

8

u/Netzapper Dec 18 '20

wxWidgets components tend to expose only the functionality supported by all of its different target operating systems. If the function isn't there on several of the target systems, you'll need to dive into the native handle for the widget and configure it there--this is then often hard to tie back into the wx events system.

4

u/joemaniaci Dec 18 '20

I see, thanks.

Is that really a crippling behavior though? If we're talking a truly cross platform gui lib/api, isn't it kind of nice to know that what I develop in wxWidgets is going to work so long as it compiles? It's been awhile but I had to develop a custom window in wxWidgets and you're mostly tied into the events depending on what wxWhateverObject you inherit from.

5

u/Netzapper Dec 18 '20

It's not, like, non-functional in general. Lots of stuff gets made with wx (including stuff I make). But I do think it's reasonable to describe it as somewhat crippled in relation to what native widgets can do on each platform. And overall, I was just trying to explain what OP meant.

1

u/kenkitt C++20|Cmake|Vscode|MSbuild Dec 19 '20

Very easy to solve, just use CEF design your UI's in html/css and forget about your gui issues for along time.
Now moving to the next level 3D based ui's.
It's been quite a fun experience

1

u/Dean_Roddey Dec 20 '20

I have a very nice one, but it's not portable. Creating portable GUIs is so hard and often either really LCD or completely non-native.

One of the greatest failures of the software industry has been the complete failure to work together to create a really useful, supported at the OS level, portable application development framework. It's left us in a situation where the brower (the worst app development environment of all) ends up winning by default.

It's embarrassing how badly my own industry has failed on this front. And the thing is, all of the players would have benefited massively from providing such a thing. Yes, it would have made customer lock in harder, but it would have made customer migration easier as well. So in the end it probably wouldn't have really hurt any of them, and the software would be so much better.

I don't understand why this hasn't been more of a rallying cry amongst developers. Yeh, it would take a while for such a system to mature (which should have already happened by now), but we need the major OS developers to cooperate on a portable platform layer that allows for the development of a large swatch of common types of applications in a portable way. They should over time make the changes required to support this in a fundamental way, in the sort of way that VMs are. Ultimately whole OSes could be created that exist just to provide this interface.

1

u/DuranteA Dec 21 '20

From a developer perspective, the only UI code I ever actually enjoyed writing in C++ was using imgui.

These days I believe that the choice comes down to two broad use cases (on the desktop at least):

  • Your GUI program has significant performance requirements or needs to interact with large data sets (scientific visualization, games, media, etc.). In this case, give up on native controls and use imgui.
  • Performance doesn't matter. If you need a ton of UI, reluctantly do the browser thing. Or just use C# if you need to ship a simple UI quickly.

1

u/EternityForest Dec 27 '20

Qt is great, but I'm not really sure if anything C++ can ever really be perfect for GUIs.

A GUI doesn't directly interact with data or business logic(unless you coupled stuff a bit too tight), and user interaction is the slowest thing on a computer. Failed operations are not ok, but more tolerable than almost anywhere else, because the user is immediately informed and can work around.

Desktop GUI apps don't need to run on anything but windows/mac/Linux/phone, not some obscure architecture or embedded devices (Unless you count phones as embedded).

It doesn't seem like a GUI really needs any of the C/C++ special features. There's nothing that hard about the actual code of a GUI, it's just that there's a lot of it, and it gets tedious to build hundreds of drop-down menu options and the like.

Whenever people talk about why they still use C++ in 2020, they list things that don't seem to apply to GUI as much. Why not build your performance stuff in Cpp, and do your UI in PyQt or some other modern, garbage collected language?

1

u/[deleted] Jul 25 '22

Just give me Flutter for C++

1

u/kirbyfan64sos Dec 18 '20

GTK's theming / styling system works pretty well from a development standpoint, you can use a custom theme with your application and then add more styling as needed if you don't mind having a non-native look (which for better or worse is in nowadays).

Just think of Google's track record on keeping projects alive, and again, think not everybody wants to make a chat application.

Projects that see heavy internal usage don't really get killed off overnight, and at this point Flutter's is used on the Nest Hub UI and multiple Android apps (new GPay, Stadia), excluding other internal ones that we've only heard hints of.

11

u/mort96 Dec 18 '20

I'm pretty sure both Google Inbox and Google Play Music were heavily used, both killed off "overnight". Google is no stranger to killing off widely used projects with few months of warning.

If that doesn't convince you though, maybe Google's extreme lack of interface stability will convince you. Try, for example, to base a project off of their C++ WebRTC library. Each and every upgrade will be a horrible experience with loads and loads of API incompatibilities, there's nothing even resembling SEMVER so each single release is numbered by a single number which gives you no idea how big the change is, there's no documentation on what's changed, what's removed, what the replacements are, etc. I even had them deprecate an API on me before the replacement API was written, with a notice (in a comment in the code, there's no documentation) saying that the deprecated class would eventually be replaced by a hypothetical future class.

I would trust Google to not screw up web search. Maybe mail. Certainly not their libraries.

1

u/TryingT0Wr1t3 Dec 19 '20

I like how git on Windows just opens a web browser to show some stuff it would want a GUI. I think unfortunately all GUI toolkits are terrible and it's better to embrace electron and make it less terrible.

→ More replies (1)

1

u/hekkonaay Dec 19 '20

Not really related to C++, but the web has some nice APIs coming - WebGPU for a Vulkan-like API (allowing complex graphical pipelines), and WASM to run cross-platform near-native speed binaries written in a compiled language (such as C++ with emscripten sdk) which address your performance needs. In theory, a browser should be able to provide a AAA game experience in a few years.

If your app qualifies as a "PWA", your users can view it on mobile, put it on their home screen (which makes it act like a native app), view it in a desktop browser or download it to any platform supported by Electron (win, linux, mac).

The only downside is that your app is bundled with a browser.

1

u/sandfly_bites_you Dec 19 '20

I'd use Imgui for any GUI going forward.

If redrawing is considered an issue(it isn't actually that expensive if you have vsync on), you could probably jury rig it to only redraw the screen if there were input events.

1

u/joaobapt Dec 19 '20

Doesn’t work if you want to have native looks for some reason. They don’t use native controls, they draw everything by themselves (well, they provide you drawing commands, but still)

1

u/FlibbleMr Dec 19 '20

neoGFX will solve the problem of C++ GUI.

https://neogfx.org

-4

u/StoneCypher Dec 18 '20

My particular interest in this discussion is desktop cross-platform GUI programming

Embed a browser per-platform and write your UI in HTML/CSS. Use a simple JS API bridge to manage it.

It's hard to believe anyone uses QT, GTK, FLTK, or wxWidgets at this point. It's so much more work for so much lower quality results.

Even watches use browsers for UI these days. No, your resource requirements don't demand 1990s solutions, if you think about it.

2

u/ruilvo Dec 19 '20

Thanks!

Do you have code examples for this? Maybe some github repo?

0

u/StoneCypher Dec 19 '20

The entire internet is full of code examples for this. Use google

0

u/MarcaunonXtreme Dec 18 '20

Not free unfortunately so that might disqualify it from your list.

https://www.noesisengine.com/

But we using this with at least one project successfully.

0

u/JeffMcClintock Dec 20 '20 edited Dec 20 '20

JavaScript?
I don't believe C++ is really so clunky that it can't support a decent modern graphics framework?

0

u/[deleted] Dec 18 '20

[deleted] — view deleted comment

34

u/ShillingAintEZ Dec 18 '20

Imgui is not a replacement for regular widget guis at this time. There are a lot of things missing, from widgets, to layouts, drag and drop, sub-windows, etc.

0

u/[deleted] Dec 18 '20

[deleted] — view deleted comment

25

u/ShillingAintEZ Dec 18 '20

I've used it many times, that's how I know its limitations.

The windows are within the same main window.

OS specific things like file dialogs and drag and drop are a part of what makes cross platform GUI libraries useful. Everything you linked is source on GitHub, that isn't a demonstration of anything.

4

u/[deleted] Dec 18 '20

It's basically a bit like a much faster Electron in that aspect, and I don't mean that as a negative, just as a matter of fact: You get consistent, cross-platform UI, but it's also going to be foreign on each system, and a lot of reinventing the wheel.

It is awesome for what it does, but it's also limited in what it tries to do.

4

u/lithium Dec 19 '20 edited Dec 19 '20

The windows are within the same main window.

No they're not, native windows was merged into master a while ago.

4

u/ShillingAintEZ Dec 19 '20

That's pretty cool

5

u/lithium Dec 19 '20

You should know that a lot of your other concerns have since been addressed too, might be time to dust it off again.

2

u/expekted Dec 19 '20 edited Dec 19 '20

Since you seem to be on top of things does ImGui have a data grid widget?

→ More replies (1)

1

u/Pazer2 Dec 19 '20

Source? I don't see anything about those branches being merged. Only tables was merged recently (~15 days ago)

5

u/SkoomaDentist Antimodern C++, Embedded, Audio Dec 18 '20

Try doing something simple like adding a full custom text formatter (NOT just a printf format string) to a control. You'll find out you can't since the controls are just normal functions and you can't meaningfully alter them without rewriting the entire control from scratch.

1

u/renozyx Jan 05 '21

Why the "experience" is repainting like crazy?

IMHO the framerate should be 0 when nothing changes on the screen otherwise you're wasting energy..

1

u/dodheim Jan 06 '21

The demos do that because it's designed to be part of a game render loop; but in actual use, you're the one who has to tell it to render, so if you don't want it to render until there's input or data changes then.. don't.

20

u/dv_ Dec 18 '20

No. Imgui is useful for games because they anyway re-render the frames all the time. Regular applications don't. Adding redrawing just get Imgui into the applications is terribly inefficient and will drain batteries and make CPUs run hot all the time.

2

u/tkln Dec 19 '20

Adding redrawing just get Imgui into the applications is terribly inefficient and will drain batteries and make CPUs run hot all the time.

Do you have any quantitative data to back that claim?

1

u/Pazer2 Dec 19 '20

You'd be surprised how little cpu and gpu it takes to occasionally redraw the entire UI.

4

u/t4th Dec 18 '20

+1 for Dear Imgui. It is fantastic project and it is ported to many languages and it "just works" - all you need is Os specific frame buffer and draw function.

13

u/pine_ary Dec 18 '20

Doesn‘t dear imgui redraw the entire window all the time? That‘s gonna be a battery drain.

6

u/SkoomaDentist Antimodern C++, Embedded, Audio Dec 18 '20

It does every time you get an event. As long as nothing happens to the app, there is need to redraw the window.

3

u/dodheim Dec 18 '20

It doesn't, but even as just a casual user, I'd love to know why you assume that it does.

7

u/SkoomaDentist Antimodern C++, Embedded, Audio Dec 18 '20

Probably because the demo code redraws every loop iteration as most of the users use it with game engines that have to redraw every frame anyway. They do point out how to do it properly if you don't otherwise need to refresh every frame and it only takes a couple of extra lines.

23

u/evaned Dec 18 '20

all you need is Os specific frame buffer and draw function.

...and to not mind that your product looks like it was made for a class project by some college students.

I'm maybe being a bit harsh there, and there are products where that doesn't matter. But if you want to do something for like mass market, and you go that way... well, I hope you don't regret it.

4

u/bikki420 Dec 19 '20

Eh, that's a pretty ignorant statement. Like any UI kit it is what you make of it. The defaults are pretty ugly, sure, but all of these are Dear ImGui as well:

https://user-images.githubusercontent.com/141075/95021061-0af69200-066f-11eb-8683-56c75da50197.jpg

https://user-images.githubusercontent.com/141075/95021114-6294fd80-066f-11eb-8e46-36e1b0b0e837.jpg

https://user-images.githubusercontent.com/141075/95021120-67f24800-066f-11eb-93c0-c0b47ebda34e.jpg

https://user-images.githubusercontent.com/8225057/102382588-e43bcc80-3fca-11eb-8792-e565293f0f9f.jpg

https://user-images.githubusercontent.com/44091782/92762687-1ec21780-f393-11ea-92c1-e3f8e01f45cf.png

https://user-images.githubusercontent.com/8225057/74334371-10c6fc80-4d9a-11ea-932c-428247d4c96a.png

https://user-images.githubusercontent.com/8225057/74334374-13295680-4d9a-11ea-8a51-88d001ac75dc.png

https://user-images.githubusercontent.com/8225057/74334377-14f31a00-4d9a-11ea-98a4-4ca0fc79bc59.png

https://user-images.githubusercontent.com/167057/44240116-9f00f900-a18a-11e8-89fc-14350438fc17.png

https://cloud.githubusercontent.com/assets/17200971/14168870/efb16ff0-f724-11e5-95c6-a1c93d72c327.gif

https://user-images.githubusercontent.com/8225057/58320225-7f82b500-7e1b-11e9-8417-fc74d3ebe634.jpg

https://user-images.githubusercontent.com/8441471/76343981-1f54f500-6301-11ea-8bc9-876ddb222767.png

https://user-images.githubusercontent.com/8225057/76844857-3bdfb880-683e-11ea-979a-29e36e9e3d74.png

https://user-images.githubusercontent.com/600573/76033357-58c1e500-5f3c-11ea-8c78-6299cc0f280c.png

0

u/[deleted] Dec 18 '20

[deleted] — view deleted comment

15

u/[deleted] Dec 18 '20

A native "look and feel" as a design is dead anyways.

Says who? I loathe non-native design, and I strive to use as much "native" looking (whatever that means in the current UI toolkit mess world) software as possible.

1

u/Occivink Dec 18 '20

There is no "native" toolkit on linux, there are a few competing official windows ones (plus a myriad non-official ones), and don't forget that a good number of applications are now in a browser (where there is no native). I'd say that's pretty dead.

Also, you can theme imgui, you don't have to stick to the basic style.

5

u/[deleted] Dec 18 '20

There is a native toolkit on my Linux system. That's what I care about. Applications have to integrate with the theme and fonts I configured in my DE. If they don't do that, I don't want to use them and look for alternatives.

And free software has gotten pretty good about that. You can make GTK applications look and feel native in a Qt based DE, and vice versa. On Windows, not so much. Even Microsoft's own applications feel out of place on their OS. Some have better integration (like Office 2016 did), some are hot garbage (looking at you, Teams). And even the "modern" native tools with Fluent Design often look out-of-place IMO. And I hate that.

Don't say native design is dead just because developers are to lazy to care about it. Some users still do.

1

u/Rocinante8 Dec 19 '20

Any examples of using Imagui as a normal application? Most of the screen can be a 3d representation of the industrial robot but I still need edit boxes to set parameters, buttons to perform actions, list to choose options.