Qt Port

Why?

The migration from GTK+2 to GTK+3 has been a nightmare, the documentation was full of deprecated, in the worst case I got X is deprecated, use Y ... Y is deprecated, use Z ... Z is deprecated. When it was finally working, not only I saw no improvement for the user compared to version 2 but in my opinion it was worst. I thought that all this time wasted to upgrade would have been better spent to switch to Qt.

Something as simple as changing the background color of an edit now requires the parsing of a CSS. Not only the upgrade to GTK+3 was hard but it's far from being finished. And when I finally managed to do something, it breaks between 2 minor revisions of GTK+. I receive bugs reports that I am unable to reproduce because I don't have the exact same version.

Switching back to GTK+2 was tempting but it would not solve everything and it isn't a long term solution.

Keeping the GTK+ Version

While it was initially a mere migration, I've decided to keep the GTK+ version, it has a better integration with GTK+ based desktops (same dialogs, same look and feel). I also find the font rendering better but may be I'm missing something with font settings or because the rendering is better with Qt based desktops.

The maintenance of 3 versions requires more tests, I don't know yet how long I'll keep all versions. At least GTK+3 should not evolve much now, I don't expect bad surprises in the future. The feedback I'll receive may help to decide whether it's worth keeping the GTK+ version or not.

Thoughts on Migration

The port to Qt was surprisingly easy, the documentation is very good, there are very few unclear parts, I've never had to deal with a deprecated function or class and I never had to skim through the source code to find what to use or to understand how to use something.

But there were some difficulties I had to deal with that I didn't have with Windows or GTK+.

Custom Main Loop

With Windows and GTK+ I could do my own message loop: It is used to validate many aspects when re-entering the message loop: title, tabs, status bar, layout, menu items enabling, ... This approach is similar to the expose/paint event: it is easy and efficient, it avoids many refreshes and computation by doing stuff only once when reentering the message loop.

But Qt does not permit custom message loops, the official recommendation is to use a QTimer with a timeout to 0. It was solved by using a combination of postEvents and timers. I emulate this for other platforms (the application uses a thin abstraction layer on top of Windows/GTK+/Qt).

Delayed Resized Events

The resized events are not emitted until the widget is visible. It happens with the QTabWidget when pages are added but not shown. It is especially annoying when you want to force a selected item or a cursor to be visible; you have to know the geometry to achieve this.

I could have kludged but I've adopted this philosophy and re-organized all my own layout system to work this way on all platforms.

C++

Contrary to Windows and GTK+, Qt has no official C API. Code Browser is written with a homemade programming language. Writing a C wrapper was tedious but not difficult, the C++ API is clean and consistent. It only needed ~900 lines of stub code.

Why not using Qt on Windows ?

The Windows version does not use Qt, it uses the native Windows API. There is a thin abstraction layer that is platform dependent.

The abstraction layer could be removed entirely and the application could use directly Qt, Qt is cross-platform, it would greatly simplify development and maintenance, so why not drop this code and use Qt on all platforms?

The only reason that prevents me to release a Qt version on Windows is that I don't want to add megabytes of libraries to a 500K program.

Using the native look-and-feel of Windows is no longer a valid reason in 2020, even Microsoft has inconsistent look-and-feel between its own products: ribbons in one application, classic toolbar in another one; title bar not consistent with system settings, ...

Resources for Migration

In case you're interested to migrate an existing application from GTK+ to Qt, here is what helpled me: