6.0.0-rc4Source

QVersionNumber Class

The QVersionNumber class contains a version number with an arbitrary number of segments. More…

Header#include <QVersionNumber>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Types

Public Functions

QVersionNumber()
QVersionNumber(const QList<int> &seg)
QVersionNumber(std::initializer_list<int> args)
QVersionNumber(int maj)
QVersionNumber(int maj, int min)
QVersionNumber(int maj, int min, int mic)
boolisNull() const
boolisNormalized() const
intmajorVersion() const
intminorVersion() const
intmicroVersion() const
QVersionNumbernormalized() const
QList<int>segments() const
intsegmentAt(qsizetype i) const
qsizetypesegmentCount() const
boolisPrefixOf(const QVersionNumber &other) const
QStringtoString() const
const_iteratorbegin() const
const_iteratorend() const
const_iteratorcbegin() const
const_iteratorcend() const
const_iteratorconstBegin() const
const_iteratorconstEnd() const
const_reverse_iteratorrbegin() const
const_reverse_iteratorrend() const
const_reverse_iteratorcrbegin() const
const_reverse_iteratorcrend() const

Static Public Members

intcompare(const QVersionNumber &a, const QVersionNumber &b)
QVersionNumbercommonPrefix(const QVersionNumber &a, const QVersionNumber &b)
QVersionNumberfromString(QAnyStringView string, qsizetype *suffixIndex = nullptr)

Detailed Description

A version number such as 6.5.1 is stored as a list of integer segments. Versions compare segment by segment, and a missing trailing segment counts as 0, so 1.2 and 1.2.0 compare equal.

QVersionNumber v = QVersionNumber::fromString("6.5.1-beta");
v.majorVersion();     // 6
v < QVersionNumber(6, 6); // true

See also QVersionNumber::compare().

Differences from Qt

The segments are always held in a QList<int>; there is no constructor taking a QSpan or a QVarLengthArray. A segment that does not fit in an int ends parsing in fromString(). compare() and the comparison operators treat a missing trailing segment as 0, so 1.2 and 1.2.0 are equal; in Qt the version with more segments is the greater one.

Member Type Documentation

typedef QVersionNumber::const_iterator

A read-only iterator over the segments of the version number.

This function was introduced in 6.6.

typedef QVersionNumber::const_reverse_iterator

A read-only iterator over the segments in reverse order.

This function was introduced in 6.6.

typedef QVersionNumber::difference_type

The type of the distance between two iterators.

This function was introduced in 6.6.

typedef QVersionNumber::size_type

The type of a segment count or index.

This function was introduced in 6.6.

typedef QVersionNumber::value_type

The type of a segment, int.

This function was introduced in 6.6.

Member Function Documentation

QVersionNumber::QVersionNumber()

Constructs a null version number with no segments.

See also isNull().

[explicit] QVersionNumber::QVersionNumber(const QList<int> &seg)

Constructs a version number from the segments in seg.

QVersionNumber::QVersionNumber(std::initializer_list<int> args)

Constructs a version number from the segments in args.

[explicit] QVersionNumber::QVersionNumber(int maj)

Constructs a version number with the single segment maj.

QVersionNumber::QVersionNumber(int maj, int min)

Constructs a version number with the segments maj and min.

QVersionNumber::QVersionNumber(int maj, int min, int mic)

Constructs a version number with the segments maj, min and mic.

const_iterator QVersionNumber::begin() const

Returns an iterator to the first segment.

This function was introduced in 6.6.

See also end() and segments().

const_iterator QVersionNumber::cbegin() const

Returns an iterator to the first segment.

This function was introduced in 6.6.

const_iterator QVersionNumber::cend() const

Returns an iterator to the position after the last segment.

This function was introduced in 6.6.

[static] QVersionNumber QVersionNumber::commonPrefix(const QVersionNumber &a, const QVersionNumber &b)

Returns the longest version number that is a prefix of both a and b.

See also isPrefixOf().

[static] int QVersionNumber::compare(const QVersionNumber &a, const QVersionNumber &b)

Compares a and b segment by segment, treating a missing trailing segment as 0. Returns a negative number if a is smaller, 0 if they are equal and a positive number if a is greater.

const_iterator QVersionNumber::constBegin() const

Returns an iterator to the first segment.

This function was introduced in 6.6.

const_iterator QVersionNumber::constEnd() const

Returns an iterator to the position after the last segment.

This function was introduced in 6.6.

const_reverse_iterator QVersionNumber::crbegin() const

Returns a reverse iterator to the last segment.

This function was introduced in 6.6.

const_reverse_iterator QVersionNumber::crend() const

Returns a reverse iterator to the position before the first segment.

This function was introduced in 6.6.

const_iterator QVersionNumber::end() const

Returns an iterator to the position after the last segment.

This function was introduced in 6.6.

See also begin().

[static] QVersionNumber QVersionNumber::fromString(QAnyStringView string, qsizetype *suffixIndex = nullptr)

Parses the leading dot-separated decimal numbers of string into a version number. Parsing stops at the first character that does not belong to the version, such as a suffix like -beta. If suffixIndex is not nullptr, it is set to the index in string where the version ends. Returns a null version number if string does not start with a digit.

string can be a QString, a QStringView, a QLatin1StringView, or UTF-8 text in a QByteArray or a const char *:

qsizetype suffix = 0;
const QVersionNumber v = QVersionNumber::fromString("6.5.1-beta", &suffix);
// v is 6.5.1 and suffix is 5, the index of "-beta"

See also toString().

bool QVersionNumber::isNormalized() const

Returns true if the version number has no trailing zero segment; otherwise returns false. A null version number is normalized.

See also normalized().

bool QVersionNumber::isNull() const

Returns true if the version number has no segments; otherwise returns false.

bool QVersionNumber::isPrefixOf(const QVersionNumber &other) const

Returns true if this version number is a prefix of other, which means all of its segments equal the first segments of other.

See also commonPrefix().

int QVersionNumber::majorVersion() const

Returns the first segment, or 0 if there is none.

See also minorVersion() and microVersion().

int QVersionNumber::microVersion() const

Returns the third segment, or 0 if there is none.

See also majorVersion() and minorVersion().

int QVersionNumber::minorVersion() const

Returns the second segment, or 0 if there is none.

See also majorVersion() and microVersion().

QVersionNumber QVersionNumber::normalized() const

Returns a copy of the version number without its trailing zero segments. For example 1.2.0.0 becomes 1.2.

See also isNormalized().

const_reverse_iterator QVersionNumber::rbegin() const

Returns a reverse iterator to the last segment.

This function was introduced in 6.6.

See also rend().

const_reverse_iterator QVersionNumber::rend() const

Returns a reverse iterator to the position before the first segment.

This function was introduced in 6.6.

See also rbegin().

int QVersionNumber::segmentAt(qsizetype i) const

Returns the segment at index i, or 0 if i is past the last segment.

See also segmentCount().

qsizetype QVersionNumber::segmentCount() const

Returns the number of segments.

See also segments().

QList<int> QVersionNumber::segments() const

Returns the segments of the version number.

See also segmentAt() and segmentCount().

QString QVersionNumber::toString() const

Returns the segments joined with dots, for example "6.5.1". A null version number gives an empty string.

See also fromString().