A Guide to Qt Programming, and the Top Tools for the Task

0
2943

Hard core Linux users prefer the power of the command line. In fact, in the early days, the command line was the sole user interface for Linux programs. As computing evolved, graphical user interfaces became an integral part of any computer application. Qt is a tool that facilitates the creation of GUIs.

Qt was primarily developed by Trolltech, a Norwegian software company that was acquired by Nokia in 2008. In August 2012, it was acquired from Nokia by Digia, a Finnish company. Qt is currently being developed both by the Qt Company, a subsidiary of Digia, and the Qt Project, under open source governance, involving individual developers and firms.

Qt is regarded as a free and open source widget toolkit for creating GUIs as well as cross-platform applications that run on various software and hardware platforms such as Linux, Windows, macOS, Android or embedded systems – with little or no change in the underlying code base, while still being a native application with native capabilities and speed. Qt allows developers to design their own program’s user interface through a method that most end users are familiar with. Most of the GUI programs are created with Qt and they have a native looking interface, in which Qt is classified as a widget toolkit. Non-GUI programs such as command line tools and consoles for servers can also be developed.

Qt supports various compilers, including the GCC C++ compiler and the Visual Studio suite, apart from having extensive international support. Qt also provides Qt Quick, which includes a declarative scripting language called QML that allows the use of JavaScript to provide the logic. Rapid application development for mobile devices has become possible with Qt Quick, while logic can still be written with native code as well, in order to achieve the best possible performance. Other features include SQL database access, XML parsing, JSON parsing, thread management and network support.

Qt editions
Qt comes in several different editions, as mentioned below.

  • Qt free edition: This is only available for UNIX/X11 and embedded systems. It contains all features of the Qt enterprise edition and can be only used to develop software that is licensed under GPL.
  • Qt non-commercial edition: This is only available for MS Windows and contains all features of the Qt enterprise edition. It can only be used to develop non-commercial software.
  • Qt professional edition: This is available for all supported platforms like UNIX/X11, embedded systems, MacOS and Windows. But it doesn’t contain certain advanced features such as the table module, the XML module and the networking module.

Fundamental technologies in Qt
Qt is built on a set of core technologies provided by the QtCore and QtGui modules, and includes the following.

  • The Tulip Container Classes: These are a set of template container classes.
  • The Arthur Paint System: This is the Qt4 painting framework.
  • The Interview Framework: This is a model/view architecture for item views and the QtSQL module, which also uses this architecture.
  • The Scribe Classes: This is a framework for creating text documents, performing low-level text layout and writing OpenDocument files.
  • Common Desktop Widgets: These are optimised to fit to support every platform.
  • Qt4 Main Window Classes: These include Main Window, Toolbar, Menu and the docking architecture.
  • Graphics View: This framework provides a canvas for producing interactive graphics.
  • QtNetwork Module: This provides support for TCP, UDP and local sockets that are integrated with Qt’s event model, including support for Secure Socket Layer (SSL) communications, network proxy servers and network bearer management.
  • Enhanced thread support allows signal-slot connections across threats and per-threat event loops. In addition, a framework for concurrent programming using Qt paradigms makes common threading tasks easier.
  • Resource system: This is for embedding images and other resource files into executable files, and it makes it easier to deploy applications.
  • Unit testing framework: This is for Qt applications and libraries.

Qt modules
A module is used for a special purpose and there are even some add-on modules that are available on all supported platforms.

Top open source tools for Qt developers
In order to assist developers in Qt programming, the following top open source tools have been reviewed to help them locate and fix bugs, and solve difficult optimisation challenges.

Figure 1: The GammaRay interface

1. GammaRay
GammaRay is a software introspection tool for Qt applications developed by KDAB. GammaRay understands most of the core Qt components from a Qt perspective – QtQuick scene graphs, model/view structures, QTextDocuments, signal/slot activation, focus handling, GPU textures, QWidgets, state machines and more – letting the developer observe and edit values at runtime in a natural way. GammaRay consists of two parts, the client and the probe. The client is the GUI that the user interacts with. The probe interacts very closely with the Qt application it analyses, using a number of internal APIs of Qt. This makes it necessary that the probe is built for exactly your Qt.
GammaRay allows the developers to work on a much higher level, with the same concepts as the frameworks they use. This is especially useful for the more complex Qt frameworks such as model/view, state machines or scene graphs. GammaRay addresses this by providing domain-specific debugging aids on a much higher level. It provides easy ways of navigating through the complex internal structures found in some Qt frameworks. Unlike the debugger, GammaRay understands those internal structures and can present them in a meaningful way, making it a tool that should not be missing in any Qt developer’s toolbox.

Latest version: 2.12.0
Official website: https://www.kdab.com/development-resources/qt-tools/gammaray/

2. Clazy
Clazy helps Clang understand Qt semantics. It displays Qt related compiler warnings, ranging from unnecessary memory allocation to the misuse of APIs, and provides refactoring actions for fixing some of the issues. Clang tools are delivered and installed with Qt Creator, and therefore you do not need to set them up separately.

CLAZY_CHECKS is a comma-separated list of checkers or check-sets to run. By default, all checkers from the ‘level0’ and ‘level1’ check-sets will run. Here are a few examples.

1. To enable the two checkers ‘unneeded-cast’ and ‘virtual-call-ctor’ only, type:

% export CLAZY_CHECKS="unneeded-cast,virtual-call-ctor"

2. To enable all checks from the ‘level0’ check-set, except for ‘qenums’, give the following command:

% export CLAZY_CHECKS="level0,no-qenums"

3. To enable all checks from the ‘level0’ check-set along with the ‘detaching-temporary’ checker, type:

% export CLAZY_CHECKS="level0,detaching-temporary"

Latest version: 1.5
Official website: https://www.mankier.com/1/clazy

3. Qt Creator
Qt Creator is a cross-platform C++, JavaScript and QML integrated development environment which is part of the SDK for the Qt GUI application development framework. It includes a visual debugger, and an integrated GUI layout and forms designer. The editor’s features include syntax highlighting and auto completion. Qt Creator uses the C++ compiler from the GNU Compiler Collection on Linux and FreeBSD.

Qt Creator is an integrated development environment (IDE) that provides tools to design and develop applications with the Qt application framework. Qt is designed for developing applications and user interfaces once, and deploying them to several desktop, embedded and mobile operating systems. Qt Creator provides tools for accomplishing tasks throughout the whole application development life cycle, from creating a project to deploying the application to the target platforms.

Features
Project management: Qt Creator needs the same information as a compiler would need. This information is specified in the project settings. Setting up a new project in Qt Creator is aided by a wizard that guides the user step-by-step through the project creation process.

Powerful user interfaces: Qt Creator provides integrated visual editors for creating Qt Quick and widget-based applications in the design mode. To create intuitive, modern-looking, fluid user interfaces, the developer can use Qt Quick.

Coding: As an IDE, Qt Creator differs from a text editor in that it knows how to build and run applications. It understands the C++ and QML languages as code, not just as plain text. This enables it to provide you with useful features, such as semantic highlighting, checking code syntax, code completion, and refactoring actions. Qt Creator supports some of these services also for other programming languages, such as Python, for which a language server is available that provides information about the code to IDEs.

Tools integration: Qt Creator is integrated with a set of tools such as version control systems and Qt Simulator, and supports various version control systems like Git, Subversion, Perforce, Bazaar, CVS, Mercurial, etc.

Latest version: 4.10.1
Official website: qt.io

4. Clang Tidy
Clang Tidy is a Clang based C++ ‘linter’ tool. Its purpose is to provide an extensible framework for diagnosing and fixing typical programming errors, like style violations, interface misuse, or bugs that can be deduced via static analysis. Clang Tidy is modular and provides a convenient interface for writing new checks. It provides a shell executable called clang-tidy as the main entry point. It is an extensible framework for diagnosing typical programming errors, or style issues — generally anything that can be detected during static analysis of the code. The real benefit of the tool is that it additionally allows users to automatically refactor the source code by applying fixes for each individual issue. It is heavily plugin-based and comes with a useful set of plugins, out-of-the-box. Clang Tidy has its own checks and can also run Clang static analyser checks. Each check has a name and the checks to run can be chosen using the -checks= option, which specifies a comma-separated list of positive and negative (prefixed with -) globs. Positive globs add subsets of checks, and negative globs remove them.

Latest version: 10.0.0
Official website: https://clang.llvm.org/extra/clang-tidy/

LEAVE A REPLY

Please enter your comment!
Please enter your name here