Some Lesser Known Qt Tools and Commands

Some Lesser Known Qt Tools and Commands - Part 4

By Jeff Tranter

In the next installment of this blog series on the lesser-known Qt commands, we'll look at the QML-related tools that come with Qt 5.

qml

This program is the so-called QML tooling, which allows running QML files directly like a script, much like UNIX shell scripts or Python programs. I've covered this specific topic before and and refer you to that previous blog post 1 for more details.

qmlbundle

Qmlbundle is a tool that allows combining resources, like QML and JavaScript files and images, into a single file. The idea is to simplify deployment by combining multiple source files into one bundle file. The current implementation is a prototype and is not mentioned in the Qt documentation. As the original developers have stopped working on it, a decision was made to remove qmlbundle in Qt 5.5.0. While it may come back again in the future in some form, currently there is no compelling reason to use this tool. Much of the same capability can be achieved by using Qt's resource system.

qmleasing

Qmleasing is a graphical application that allows you to experiment and visualize easing curves. You can use the tool to assist in getting the desired effect, after which you copy and paste the control points into your code. A screen shot of the tool running is shown below. For more details, see the documentation for the QEasingCurve class.

Snapshot

qmlimportscanner

This tool parses and reports on QML imports to assist in deployment, so that the necessary QML modules are deployed as part of the application. It is used by Qt Creator and by the Mac OS X deployment tools.

qmllint

Because QML is interpreted at run-time, rather than compiled like C++ code, errors can go undetected until the offending code is executed, possibly when the end user is running it. The qmllint program, new in Qt 5.4, is a tool that checks QML files for correct syntax. It can be useful to run as part of a Continuous Integration (CI) system to detect errors at build time or on code check-in. It is covered in detail in this blog post 2. The tool is quite new and does not detect all possible errors, but can be useful for catching errors earlier in the development process.

qmlmin

The qmlmin program is a utility that "minimizes" a QML file, removing comments and layout characters. It can optionally restrict the output to a specific width. It is useful for reducing the size of QML code that needs to be deployed, resulting in smaller executables (when the code is stored as resources) and installers.

As an example, when run on the following simple QML example program:

// Simple QML example
import QtQuick 2.4
Rectangle {
width: 640
height: 480
Text {
anchors.centerIn: parent
text: "Hello, world!"
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit()
}
}
}

The output is this smaller, but equivalent, one line program:

import QtQuick 2.4;Rectangle{width:640;height:480;Text{anchors.centerIn:parent;text:"Hello, world!";}MouseArea{anchors.fill:parent;onClicked:{Qt.quit();}}}

Obviously, you will want to keep and work with the original commented and formatted QML code, and only use the minimized code for delivery.

qmlplugindump and qml1plugindump

The qmlplugindump utility is used to generate a .qmltypes type description file. These files are used by tools like Qt Creator to obtain information about the types used by plugins, so it is good practice to ship a type description file with QML plugins.

Qml1plugindump is a similar tool that works with Qt Quick 1.

For an example of using the tool to generate a .qmltypes file, see the Qt documentation section entitled "Using QML Modules with Plugins".

qmlprofiler

The Qt QML module provides facilities for debugging, inspecting and profiling QML code via a TCP network port. The Qt Creator IDE provides a user interface for performance profiling of QML code.

The qmlprofiler command line tool is provided to capture profiling data to a file. It can be useful if you are not using Qt Creator or want to integrate profiling into some other development tool.

qmltestrunner

The qmltestrunner utility facilitates running unit tests on QML code written using the Qt Quick Test unit test framework. It isn't currently documented very well, but I was able to find a tutorial 3 that was written as part of the Ubuntu developer documentation.

Summary

I hope you enjoyed this look at the QML-related Qt command line tools. Looking ahead, there are still more tools to cover, enough for at least one more installment in this blog series.

References

  1. The Whole Shebang - Running QML Files Directly, ICS blog post, accessed 1-Jun-2015, www.ics.com/blog/whole-shebang-running-qml-files-directly
  2. KDAB contributions to Qt 5.4: qmllint, KDAB blog post, accessed 1-Jun-2015, www.kdab.com/kdab-contributions-qt-5-4-qmllint/
  3. QML Unit testing, Ubuntu developer documentation, accessed 1-Jun-2015, docs.ubuntu.com/phone/en/apps/qml/tutorials-qml-unit-testing