You are here

What's New in Qt 5.6.0: QVersionNumber

The Qt 5.6.0 release, coming in early 2016, includes a number of new modules and classes. I plan to cover a number of these in a series of blog posts. In this first post, we'll start with one of the simpler classes in Qt 5.6.0: QVersionNumber.

Basics

Part of the Qt core, it provides a facility to manage version numbers. In this context, version numbers are defined as an arbitrary number of segments, which are numbers separated by dots or periods. A version can also have an arbitrary suffix added to the end.

The following are examples of valid version numbers for the QVersionNumber class:

1.0
1.2.3
3.4.5.6.7
1.2-alpha
3.4-rc1

While it is supported by QVersionNumber, it is rare for software to use more than three levels of numbering. For convenience, the first three segments are referred to as major, minor and micro respectively.

The class has the concept of normalized versions, where trailing zeroes are removed. This allows version strings like 5.6 and 5.6.0, for example, to be considered equivalent.

Provided by the class are a number of constructors that can create an empty QVersionNumber, an instance given major, minor and/or micro versions, or even from a QVector or C++11 initializer list.

The class provides a number of useful methods to perform common functions such as getting the major version, normalizing, converting to a string and comparing two versions. It also provides suitable operators for comparison and QDataStream input and output.

The QVersionNumber class is for use from C++ only, no QML interface is offered.

Code Example

The following is a simple non-graphical Qt program which demonstrates some of the basic features of the QVersionNumber class. I encourage you to download the source code (1) and try it out yourself.

Summary

In Qt 5.6.0, Qt uses the QVersionNumber class internally in a few places, but not in any public APIs. Possibly in the future Qt will make more use of the class. I can imagine for example, having a method that returns the Qt version as a QVersionNumber or perhaps the QCoreApplicationapplicationVersion property. The QDataStream class has support for version numbering that could possibly use this new class, although it would need to do so in a way that remained binary compatible.

In summary, the new QVersionNumber class is quite easy to use and the documentation explains it in detail.

Note that this blog post was based on the Qt 5.6.0 beta version and changes may still occur before final 5.6.0 release.