Qt Components

Source (link to git-repo or to original if based on someone elses unmodified work): Add the source-code for this project on


A data type for version numbers.

This class provides a data type for version numbers. Think of it as a QString which provides special behavior for version numbers in the six relational operators (=, ==, !=).

The behavior of the relational operators is similar to the behavior of RPM when comparing versions. "Similar" means that it is not equal! See for a good description of the algorithm used by RPM to determinate version ordering.

You can assign values of the type QString and even qint64 (which will be converted to a QString) and of course of the type VersionNumber itself to it. You can use the assignment operator or the constructor for initiation. The data type is made available to QMetaType and is this way available in for example QVariant. If you want to use it in in non-template based functions like queued signal and slot connections, do something like int id = qRegisterMetaType("VersionNumber"); at the begin of your main function. This will register the type also for this use case. id will contain the type identifier used by QMetaObject. However, for most cases id isn't intresting.

You can convert to a string with toString(). This function returns always exactly the string which was used to initialize this object.

To compare version numbers, the QString is segmented into small parts. See for details. The algorithm of VersionNumber differs in some points from the algorithm of RPM:

* It accepts all strings, also with special characters.

* You can use not only "." but also "-" as often as you want. (Each new dash separates a new part in the number.)

* You can safely use special characters. If they aren't "." or "-", then they are treated as normal characters. The very last segmentation (e.g. "12#rc1" to "12", "#", "rc", "1") does not only differ between QChar::isDigit() and QChar::isLetter (like RPM does), but has a third category for characters who are neither digit nor letter.

* The very first occurrence of ":" is treated as separator for the epoch. Each following occurrence of ":" is treated as normal character.


5 years ago

Thanks a lot for your nice VersionNumber class!


product-maker pbe78 Sep 29 2015 9 excellent
Be the first to comment
Sep 29 2015
File (click to download) Version Description Downloads Date Filesize DL OCS-Install MD5SUM
*Needs pling-store or ocs-url to install things
0 Affiliates
updated May 15 2010
added May 15 2010
downloads 24h
mediaviews 24h 0
pageviews 24h 0
System Tags