This post is an introduction to the next several posts. If you’re bored with QtQuick introductions (since there are many)… then there’s probably nothing to see here.
Composite (and its ancestor Hydrogen) has always had a Qt UI. And when it comes to GUI, Qt is the toolkit that I prefer to use. Why Because I really don’t like UI development. I like to work on models, business logic, complex calculations, etc. I really get bored with sizing widgets and trying to figure out how to convince the font system to give you the real, actual, true bounding rectangle (and not the one that’s better for typesetting).
And then there’s the code. The options have always been something like:
- Use a C API like GTK+ and write gobs of code and manually
type all the gtk_widget_* namespaces for every class method.
- Use a C++ API wripper like gtkmm (which never really gets
rid of the smell of the C API).
- Write gobs of Qt code to express your UI. Which means that
small changes (like moving a widget from here to there) often
require a lot of code changes.
- Use a UI designer to create XML files that get processed into
code. (I.e. Qt Designer or Glade.) While it’s easy, these
files often have compatibility issues even across minor
releases. They also are not very diff friendly (which is
important to a backend-loving code monkey like me).
- Write your UI in a scripting language like Tcl/Tk or Python
(e.g. the PySide bindings). Here you trade-off flexibility
for simplicity a lot of the time. (Think: custom widgets.)
These options all have one thing in common: they suck.
Along comes QtQuick, with the idea of expressing your UI in a scripting language called QML. QML is:
- Declarative/Interpretive: so small changes just require that I refresh the QML file in question… not recompile (or even restart) my whole application.
- Designer-friendly: if your project has an artist, they probably aren’t very good at C++. QML isn’t too difficult to parse… which makes them more productive.
- Developer-friendly: as a C++ lover I’m not crazy about the syntax of QML… but I love that I can throw up a UI pretty quick. While the UI’s that I design look like butt… I don’t feel like I have invested a lot of code into something that needs to change (and change a lot) later in the project.
- Architecture-friendly: It more or less enforces that you use a model/view architecture in your application. When the UI was code, it’s very tempting to pragmatically break the rules.
- Promising: The Qt framework is reorganizing itself around QML. It’s pretty fast now, but it promises to be blazing fast in Qt 5. (Even faster than using native widgets or QGraphicsView… and that’s an impressive accomplishment.)
However, it does come with a few drawbacks:
- It’s oriented to embedded devices that have a fixed-size, full-screen “app” paradigm. Therefore, you’ll find that lots of sizes and relationships are set in fixed-size pixels. It’s not quite as nice as QLayout in C++. This means it’s still a little… primative in a desktop context.
- The scripting language is kind of… strange. It is very weakly typed (e.g. inspecting the code you can’t be sure if a symbol is a property or a method or a signal or an element or a reference to a C++ class). This is really, really confusing.
- The language uses a sort of “inner class” idiom like in Java.
- It’s interpreted, so typos likemy_symbol/mySymbol will not be detected until run-time. (In fact, this is a drawback of Qt signals/slots as a whole.)
- Concepts like QAction and QMenu are missing, and will probably never be added. They’ve been branded as obsolete, old thinking with respect to UI design. While I don’t necessarily disagree… the loss of them takes some getting used to.
All in all, I think that the good out-weighs the bad.
Since I don’t know how to use QML effectively, the following few blogs will share my journey and what I’ve learned. I’ll do so by writing a very simple calculator application.