Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I join a QT GUI to a non-C++ main program?

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?

like image 306
Demi Avatar asked Oct 02 '14 14:10

Demi


People also ask

Does Qt support C?

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

Is QT best for GUI?

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.


1 Answers

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 :)

like image 60
Vladimir Matveev Avatar answered Oct 06 '22 00:10

Vladimir Matveev