QVersionNumber Class
The QVersionNumber class contains a version number with an arbitrary number of segments. More…
| Header | #include <QVersionNumber> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| typedef | const_iterator |
| typedef | const_reverse_iterator |
| typedef | value_type |
| typedef | difference_type |
| typedef | size_type |
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) | |
| bool | isNull() const |
| bool | isNormalized() const |
| int | majorVersion() const |
| int | minorVersion() const |
| int | microVersion() const |
| QVersionNumber | normalized() const |
| QList<int> | segments() const |
| int | segmentAt(qsizetype i) const |
| qsizetype | segmentCount() const |
| bool | isPrefixOf(const QVersionNumber &other) const |
| QString | toString() const |
| const_iterator | begin() const |
| const_iterator | end() const |
| const_iterator | cbegin() const |
| const_iterator | cend() const |
| const_iterator | constBegin() const |
| const_iterator | constEnd() const |
| const_reverse_iterator | rbegin() const |
| const_reverse_iterator | rend() const |
| const_reverse_iterator | crbegin() const |
| const_reverse_iterator | crend() const |
Static Public Members
| int | compare(const QVersionNumber &a, const QVersionNumber &b) |
| QVersionNumber | commonPrefix(const QVersionNumber &a, const QVersionNumber &b) |
| QVersionNumber | fromString(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().
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.
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.
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().
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().
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().