Qt Works pretty well

I've been looking for a development platform that can let me create programs which work across all major operating systems. While there is nothing wrong with scripts and scripting languages, sometimes a GUI just makes sense. In the past I've used WinForms in C# to create utilities with functional user interfaces, but now that I'm looking to switch to Linux full-time I'd like something which is about as easy to use that can target at least Linux and Windows.

Qt appears to check all the boxes I need, so barring development of a WinForms-like option for .NET Core or other changes in the landscape I'll press on.


Initial Setup

My background includes a fair amount of QT development for BlackBerry OS 10 devices (back when those were still being manufactured- I even attended the BlackBerry Jam 2012 event in San Jose), so transitioning to the 'Desktop' side of things ended up being fairly trivial. The QtCreator tool is pretty slick and includes a Designer tool that can be used to mock-up and layout graphical interfaces which can be wired up to code in a way that feels a lot like the WinForms editor in Visual Studio (my primary reference point for this sort of thing).

The hardest part to getting setup with Qt for me was identifying the download link for the Open Source edition. I don't need mobile development or any of the other 'commercial' features for the desktop utilities I write. While the main site does mention the 2 different licenses that Qt is distributed under (LGPL and Commercial), the Open Source Edition takes a bit of searching to find.

For anyone new to Qt there are conceptual hurdles (like Signals/Slots, C++ conventions [for those coming from higher level languages]) as well as Qt specific configuration settings that will eventually need to be understood (such as the settings in the '.pro' config file) to create useful, working software.

Compiling Cross-platform

It is not too difficult to create statically linked executables that can run independent of Qt libraries being installed on target machines, though there are licensing implications that come in to effect based on the Qt license you choose to use. I use the Open Source edition licensed under the LGPL since it can create programs that are either open source or proprietary in nature. The tools I distribute are all released under open source licenses ranging from MIT to GPL, so the ability to create proprietary software is not too important on that front. It is nice to have the option if it ever makes sense, though.

Qt adopts a philosophy of "Write-once, compile anywhere". This makes it easy to build a platform-native executable on any system that can run QtCreator (at present this includes all modern variants of Windows, Linux and Mac). But what if you want to cross-compile a Qt application for another platform?

I specifically want to be able to write Qt applications on Linux and cross-compile them to run on Windows. To do this easily, I leverage the hard work of the MXE project. They provide makefiles that "compiles a cross compiler and cross compiles many free libraries such as SDL and Qt." Using their makefiles I was able to successfully cross-compile for Windows.

Cross-platform Distribution

(Cross-)Compiling is not the only step needed to generate an executable suitable for distribution. If you want your program to work independent of the version of Qt that may (or may not) be installed on your end users system, you have a couple of options:

  • Compile a statically linked executable (harder to maintain LGPL compliance)
  • Compile a dynamically linked executable and distribute all relevant Qt dependencies

There are a number of libraries and QT Plugins that need to be copied to your executable directory if you go with the dynamically linked option. I choose the dynamic path to make it easier for me to stick with the requirements of the LGPL. See the References at the top of the post for help on knowing what to include in your Qt project directory (and where).

Final Thoughts

Given that I was able to find a community/LGPL licensed edition of Qt, this meets all my requirements for a cross-platform framework that I can use to develop tools and utilities. My previous experience with Qt lets me quickly jump in and make the best use of the platform and tooling.

Compared to other options that I've evaluated (like Mono/GTK# and Electron), this solution provides the quickest path for me to create a GUI-enabled tool or utility that has a high-degree of usability. I'm sure that I could get either Mono or Electron to meet my needs with time and fiddling (both are highly functional solutions). Qt happens meets all my needs now and has advantages over Electron (such as small executable size and a GUI designer) and Mono/GTK# (requires a CLR to be installed, GTK# can be fiddly).