The Complete Magazine on Open Source

Qt: What’s best about the cross-platform development toolkit

Check out Qt, a cross-platform development framework, which can be used to develop applicatio software that runs on various software and hardware platforms.

Qt, which is pronounced as ‘cute’, is a cross-platform development framework which was originally created by Haavard Nord and Eirik Chambe. It was first released on May 20, 1995. The latest version, Qt 5.8, was released on January 23, 2017. Qt comes in four editions— Community, Indie Mobile, Professional and Enterprise. The Community version is under the open source licence, while the other three are commercially sold by the company, Qt.

Qt is not a programming language at all but a cross-platform development framework for the desktop, embedded systems and mobiles. It is basically written in C++. The ‘t’ in it stands for ‘toolkit’ which describes it much better. It is, in fact, a set of tools. Remember that it is written as ‘Qt’ and not as ‘QT’. The first letter stands for Apple’s QuickTime and has very little to do with programming. Thus the framework itself and the applications/libraries using it can be compiled by any standards-compliant C++ compiler like GCC, ICC, MSVC and Clang.

Figure 1: Qt Creator

Figure 2: New project

Its purpose and capabilities

Qt is used for developing multi-platform applications and graphical user interfaces (GUIs). However, programs without a GUI can also be developed, such as command line tools and consoles for servers. An example of a non-GUI program using Qt is the Cutelyst Web framework. GUI programs created with Qt can have a native-looking interface, in which case, Qt is classified as a widget toolkit.

It uses standard C++ with extensions, including signals and slots that simplify the handling of events, and this helps in the development of both GUI and server applications. Qt supports compilers like GCC and the Visual Studio suite. It also provides Qt Quick, which allows the use of scripting languages like JavaScript. Non-GUI features include SQL database access, XML parsing and JSON parsing.

Downloading and installing Qt

Download the copy of the Qt SDK or if you are using a Linux system, then use a copy of Qt and a compiler. Remember that if you are starting off, you might want to consider the open source LGPL version.

Qt can be installed in two ways:
1. Through the Qt installers, whereby you download and install it.
2. Through the Qt source.

Figure 3: Qt GUI

Figure 4: Select path

Creating a new project

The following steps will help you create a project.

Start up Qt Creator (refer to Figure 1). Go to the File – New File or Project menu entry.
Choose Qt GUI Application and choose a name for it (see Figure 2). Enter a project name, say ‘qt-tutorial-01’ (Figure 3).
Select one or more versions of Qt to target. A desktop build is fine for this tutorial (Figure 4).
Select the base class to be QWidget and for everything else, leave it as the default settings (Figure 5). Check the project creation options on Summary and click Finish (Figure 6).

This will create a simple project consisting of four files.

  • main.cpp
  • widget.h
  • widget.cpp
  • widget.ui

Figure 5: Select Baseclass

Figure 6: Summary

Facts and features

  • There were one million downloads of Qt 5.3 in just over a month after its launch.
  • There are 250+ commits by over 60 contributors per week.
  • Companies that use Qt include AMD, Autodesk, Siemens, Panasonic, etc.
  • Alongside the support for traditional desktop user interfaces, Qt includes support for declarative UI development with Qt Quick.
  • Widgets can be used for painting, printing and rendering.
  • Integration between Qt and WebKit makes it possible for developers to use a fully-featured Web browser engine.
    The Qt framework is simple and user-friendly. Once you understand how this simple app works, you can start adding some more bells and whistles like signal/slot connections.