Building Applications with Qt and boost

by Jens Weller

This is the start of a series of posts, in which I'll try to document my weekly work on a new application, build with Qt and boost. This first post is rather short, but I'd quickly try to give you an overview, why I use both Qt and boost in the same application. Regarding Qt, I wrote an introduction a two years ago, also for boost, there is an excellent website/tutorial about boost by Boris Schäling (buy his book! ;)). This series is not meant as a general introduction, yet I try to show you how and what I use of Qt and boost.

Why I use Qt

Qt is the framework and library set I use the most in my daily work. It offers a good and mature UI implementation with QWidgets, but also has with QML a modern UI which you can use for mobile, desktop or embedded Apps. I also like that Qt has a very nice DB API, offering many different Databases, yet I end up only using SQLite so far. Also, with its model/view system, Qt offers me an easy way to do display and edit my data in Qt. It is actively developed, and releases about twice a year a new version. Qt has updated its sources to C++11, and continues so for C++14, but as Qt is a huge code base, this takes time. Qt traditionally does not expose a lot of templates and fancy C++ to the user, so that working in Qt and with Qt APIs is relative easy to get a lot of work done. Also, with the Qt SDK ships a new version of QtCreator, which is a really nice cross platform IDE with great Qt integration. It is my preferred workhorse for C++ today, also because I use Qt so much I guess...

...which brings me to the few things I really don't like about Qt. To be honest, its not the moc, which gets its fair share of critics from the C++ Community. Qt does a lot of things with the Meta Object Compiler, which currently aren't possible in C++. My biggest groom with Qt is, that it does not really allow or understand the generic potentials of C++. I like that Qt does not expose it so much to the user as boost does, but as an advanced user, I'd like to see more possibilities to combine Qt and templates/generic programming. One thing which makes this really difficult, is that QObject derived classes can't be templates, as the MOC isn't smart enough for this. So every class that is involved with Qts inner workings, such as signal and slots, is a concrete class. Qt offers a few interfaces for C++11, such as using lambdas as slots. Also Qt locks you into this one big framework, which has advantages such as compiling across many platforms, but also means, that often you don't have the need to work with the standard or boost. But when you write more then one application, you start too see the benefit of writing generic code, which is where boost comes in...

Why I use boost

I don't use boost as much as I could, often I already have an alternative in Qt (filesystem e.g.). Where boost really comes to shine is, that it is essentially a toolbox, full of helpful little libraries, plus a few big libraries handling things like parsing, filesystem, sockets, threading or GPU computing. While boost is more a collection of libraries (more then 120 already), it is also a little bit a framework, but often parts of it can be simply used as a generic tool to easily implement the needed code for your application. Especially when writing generic code boost is a great tool, as it has always embraced the generic nature of C++. One of its great advantages is, that it is very close to the C++ standard, and many of its libraries serve as blueprints for the standardization in C++11 through C++17. Also some of its libraries, already offer features of future standards, such as the threading library has already .then for futures. Also, boost offers many of the standard libraries in a C++03 compatible way. Also, boost offers implementations for flat containers and other useful helpers (string algorithm, more then one regex impl e.g).

There is no elephant in this room. Boost seems not to have disadvantages, except its documentation, bringing its own build system (though many libraries are header only, and Qt has qmake AND QBS) and longer compile times. A friend once coined it in that boost is more academical, and Qt more practical for daily work. Especially the documentation is in my opinion a problem, as it sometimes lacks detailed examples, and sometimes its hard to find out the correct usage without digging for some time through google and/or stackoverflow.

But lets talk about the elephant. I've been 4 times to C++Now, there isn't really a better place to get a feel for the boost community. But sometimes you also can meet this elephant at the boost mailing list. One problem boost was facing in the last years, is actually the C++ standardization. C++11 brought the first libraries from boost to the standard, a few are on the way. C++11 also brings changes to the language, such as template meta programming, huge parts of boost emulate variadic templates, now its in the standard. Boost has a huge pre C++11 code base, that needs to adapt to the new changes too. So, in the last years, at C++Now you clearly could see people worried about the future of boost. After all, standardizing the good parts and dropping the rest would have been an option. With github people have a place to put up there C++ Libraries and many do. Also, with boostcon renamed to C++Now, would the good, and cherished boost content of the conference be replaced by the newer, hotter C++11 and standardization topics?

The good news is, from 2014 on (the 3rd C++Now) one could clearly see, that things were also changing in boost. There is now the boost incubator, making it easier to submit libraries to boost. There is a new generation of boost libraries build with C++11 and C++14, though boost probably will have a few legacy libraries, which will or already have found their replacements. For example boost::tmp -> boost::hana. But boost is not alone with this problem, the fast forward moving C++ standard poses a problem in adoption and refactoring for all C++ frameworks and libraries. Especially for the older ones, build around OOP, C++03 and java-like ideas.

The coming series

So I use Qt mostly for UI and Database related parts, while boost helps me with writing generic code, which I could reuse later. In all parts of my work, it is an important focus for me, if I could reuse some of the code later in a different C++ project. Also, I'm in a little very special situation: I'm my own project manager, tester, coder and end user. Most of my coding today is done on tools I actively use every week. Yet, some of my code runs only once a year, but that is not such a big issue for this new application.

I plan to work on my new application mostly on Mondays and Tuesday, so that I can blog on Wednesday or Thursday about my code from last week. This is to give me a week to think of the chosen implementation. I also plan to make short videos showing my progress. The next entry will be about tree views and how to build models for them in Qt. I don't want to disclose directly on what I'm building, just to keep you guessing :P

Teaser video:


Go back

Follow Meeting C++