Things i've made

Looking for more? See a list of everything i've made.

Sunday, July 10, 2011

Convert a Gtk Application into a Qt Application ?

So, it has been tasked upon me to take a very large Gtk application, say millions of lines of code, and plan a path for it to exist without Gtk. Why move away from Gtk? Well this application work extremely well on linux and solaris, yet it seems to have continual issues regarding Gtk on windows. I would go into the exact details here, but I do still like Gtk for what it does, I just wouldn't consider writing a large application with Gtk if Windows was going to be one of the target platforms.

So I have a few options on where to go from here. I basically need to have the application work well on linux, solaris, and windows, use only one code base so C#/WPF is out of the question, and also importantly, not take forever to move away from Gtk. The obvious alternative is Qt, but how do you move such a large application to Qt without halting development ?

A first approach I tried was to create an easy way for Qt QWidgets to co-habitate with Gtk GtkWidgets. This is not too difficult, on linux and solaris you can use the plug and socket implementation, and on windows you can pass a native window ID to a QWidget to parent it inside a different widget system. These systems have been used by web-browser plugins for yonks, so no big deal. You can see my results below.
Gtk and Qt widgets inside the same window
Allowing both widget libraries to co-exist in the same application allows for a slow but smooth transition without halting new development, excellent! Only problem is that word - slow. How long do you think it would take to convert a million lines of Gtk code to Qt ?

So, my second approach, based somewhat on what others have attempted, is to implement Gtk's API to use Qt as its backend. Others have made wrappers or thin bridges between Gtk and Qt doing something quite similar. Nowhere had I found someone who had made enough progress to actually compile a useful application. Since getting a good wrapper implementation was going to save a lot of code being written it seemed to make sense to make a full attempt at the task. Below are some of the gtk-demo applications that have been compiled with my wrapper - no source code changes what-so-ever. Just point your compiler and linker to different include and link directories and you are done.

Gtk demo applications compiled with Qt wrapper running on Linux
Now let me straight up tell you, I don't aim for 100% functionality. You can already see some parts i've not cared about such as some more advanced combo boxes, streaming images, 100% correct packing and alignment, etc. I'm not after perfect right now, just after working, and if my target application doesn't use a feature of Gtk, Im not going to have the wrapper implement it either, this is about saving time, not perfection!

If this project interests you, you would like to discuss what you see here, or want to ask about getting a copy, feel free to contact me.


  1. hi, I would like to have a try of your wrapper. I would want to convert a diagram program written in gtk+ ( and integrate it with my qt GUI. My email is Thks

  2. Hello - if this still valid, I am trying to convert some OSS apps to osx (geomorph, sharp3d) for some time and this wrapper could be a great help for me - I think - I would like to try it, if possible: my email:


  3. I tried sending an email but to no avail, so I'm taking a stab here, I'm interested in obtaining your wrapper

  4. It would be awesome if this was public somewhere (like github?). I am sure that several people would like to "play" with it, especially if your wrapper + gqt + gtk-made-qt could join forces.

    In fact, it would be cool with several widget toolkit re-implementations in Qt. There was an old compatibility for Motif in Qt3 for example (not including Xt, but if Xt would be wrapped to Qt too, one could recompile a Motif application to a pure Qt application).

    I am guessing that you are doing like the other two wrappers - most conversions via the pre-processor using wrapper headers and then perhaps a small static library for re-implementation of functions that lack 1:1 conversion possibilities?

  5. hi, I would like to have a try of your wrapper for test.


Note: Only a member of this blog may post a comment.