Mod developer of older games. These include: Ground Control II, Sins of a Solar Empire (Rebellion), Freelancer, FreeSpace 2 (SCP), Allegiance, Rome: Total War, Independence War 2, and some little stuff here and there. Currently only the GC2 mod is available.

Report article RSS Feed Qt is the chindōgu of GUI programming

Posted by Flamecurse on Mar 10th, 2014

..or at least, its documentation is.

While I do enjoy modding games (especially ones with intuitive code and good debugging tools; Sins of a Solar Empire tops the list out of all the ones I've worked with) I have always kept my distance from the programming aspect of things. I've gleaned enough over the years to have a broad idea of how the inner workings of many games function, but have never had any desire to modify or replicate it.

When I started working on version 3 of my Reversal mod back in January one of the ideas I came up with was to make a small launcher program with a menu GUI to let you select which variation of the mod to play on. In older versions (and the original Terrans mod) the easiest way to do this was to hand out batch files and/or instruct people on how to configure their shortcuts. I figured a menu would be far more user-friendly, picked up a C++ IDE and went looking for some tutorials on how to get started.

Learning to program took a backseat to developing the mod, but near the end of development I found out that there was a C++ derivative called Qt. It built on what I had already learned and was much easier to use for creating GUIs. And it really is. Just not for a beginner.

There is a wealth of documentation on Qt, both official and unofficial. The official stuff is paradoxically informative yet unhelpful, a good reference for someone already familiar with the language but too nebulous to be useful for someone just getting started with it. It does a good job explaining syntax, but doesn't provide anywhere near enough concrete examples to show how it should actually be used. Parts of the language that claim to do something either require additional undocumented steps to function properly or have simply been broken or deprecated.

The unofficial documentation is whatever you can find through search engines and a good half of it - helpfully linked to by experienced programmers - is located on websites that either don't exist anymore or are so out of date that attempting to follow along only makes the problem worse.

My experience with getting a simple launcher menu to work amounted to a week of headache-inducing frustration scouring through search engine results and the official documentation. It was an effort to piece together the full picture on how to do things I would consider to be some of the most basic parts of the whole programming language: Create one window, press a button, get result. Not all parts of this were painful, indeed some things turned out to be well documented, exampled and painless to bring into effect.

On the other hand I lost two days just trying to figure out why any significantly-sized program would crash if started by the launcher: It turns out that Qt instructs any program it starts to run in the launcher's directory rather than the program's own. While I feel this is counter-intuitive, it wouldn't have been a problem if ANY of the examples, guides or documentation mentioned it. I was saved instead by some very helpful startup crash error messaging in one of the games I tried it with. Once I realized that I had to set the working directory manually, and figured out which methods to do so actually still worked the whole thing didn't take much time to finish. All I had left to do was pack it up and include it with the mod.

Well, the frustration wasn't over yet and neither were the headaches. See, there's two ways to make a program: Pack the library files it needs into the .exe or just include them with a package. These libraries are the bridge between an operating system and the programming language; In short they're needed so that the computer knows what to do with my code.

I was hoping to put everything into the executable and not worry about clogging up my mod users' system paths with these relatively obscure library files. Long story short, I'm just going to paraphrase someone I read on a YouTube tutorial's comments section: "Watching paint dry would be more productive than trying to learn how to statically compile Qt." I wish I had read that first, it would have saved me a lot of time.

By this point I had pretty solidly burned out on the whole project in general and the programming in particular, and I just wanted it over and done with. So I figured fine, lets just include the libraries with the mod and not worry about how inefficient or ugly it might look. So long as most or hopefully all of the users don't have any problems getting it to run I'm satisfied. And that brings me to the whole point of writing this blog:

The launcher I made is a mere 90 kilobytes. It would fit on an old floppy disc from the 80s several times over with room to spare. The libraries required for it to run are a mind-blowing 45 megabytes. That doesn't even include the ones Windows users should already have. 45MB for a menu and some buttons is beyond unreasonable, its outrageous. The size isn't even the worst of it, these are nine different .dll files taking up all this space. I would have thought the most basic, common functions would be in their own small library, and as you got to creating larger and more complex programs the libraries you'd need for all the specialist code would scale with it. Not so. Instead even the most bare-bones program with Qt requires all of these same libraries to run. Sprinkling all the different bits of basic code into a slew of different libraries just seems ridiculous to me for a default, out of the box configuration.

I'm sure there's a way to make it more streamlined but I'm neither experienced nor patient enough to try. Just getting to the point where changes could be made required downloading (and/or learning) Microsoft's version of the C++ tools (in addition to the ones I was already using) along with Python, Perl and Ruby and then getting them configured on my system. All to put the Qt source code together so I could go back to learning how it works, so I could maybe shrink the library sizes down or get it to static compile. Rube Goldberg could've invented less convoluted systems than this.

So if any of you are wondering why the entire mod package has ballooned in size, this is it (aside from all the new map and model fixes). But at least it works.

Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Level
Avatar
Avatar
Offline Since
Sep 19, 2014
Country
Canada Canada
Gender
Male
Member Watch
Track this member
Blog
Browse
Blogs
Report Abuse
Report article