QT appears to be the best cross-platform GUI toolkit available. Unfortunately, it is in C++, and bindings for it to many interesting languages (such as D, Rust, Julia, and Mono on *nix) are either not available or not maintained. GTK bindings are usually available, but GTK looks ugly on Windows and (especially) OS X. wxWidgets bindings would also be nice, but are not available or are unmaintained for D, Rust, and Julia (For Julia, I could go through Python for both toolkits, but that is slow and clumsy).
How can I bind my C++ GUI to an non-C++ main program?
Short answer: no. If you need a comprehensive GUI toolkit for C, you can use GTK+. To use Qt, you must have a C++ compiler. But it doesn't mean that your "application logic" can't be written in C, compiled with a C compiler and carefully linked to the C++ part (the GUI with Qt).
Qt is de-facto the most suitable framework for the commercial application of a cross-platform GUI library available for C++, Python, Go, Haskell and some other languages. Of course, developers are free to choose from among many other frameworks for designing user interfaces: wxWidgets, JUCE, CEGUI, Tk or even GTK.
You have a handful of options here.
First of all, you can bind your GUI and your main app via C API. GUIs are usually done via callbacks which are invoked through an event loop, so you will have to expose functions in your high-level language as C callbacks in order for them to be called from the event loop. Then you will need to start Qt event loop. There are multiple ways to do it depending on which language you use. For example, if you use Rust, you can make a static or dynamic library and link your C++ GUI program to it. In this case the "entry point" of your program will be the C++ part. If you use something like Julia, you will probably want to compile the C++ part as a library which would also expose a function which calls Qt event loop. So in this case the "entry point" will be your higher-level part which still would need to call back into the C++ library.
The second approach is closer to web UIs. You can make your GUI a client for your main app written in another language. They can exchange messages through some existing protocol, like HTTP, or you can implement your own protocol over a low-level TCP or UDP connection, or you can use "middle-level" messaging library like ZeroMQ or nanomsg. You can also consider dropping Qt altogether and just write a web app, with your program as a web server. This is the most cross-platform way to write a GUI now, I guess :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With