QVersionNumber Class
The QVersionNumber class contains a version number with an arbitrary number of segments. More...
Header: | #include <QVersionNumber> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
This class is strongly comparable.
Public Types
(since 6.8) | const_iterator |
(since 6.8) | const_pointer |
(since 6.8) | const_reference |
(since 6.8) | const_reverse_iterator |
(since 6.8) | difference_type |
(since 6.8) | pointer |
(since 6.8) | reference |
(since 6.8) | size_type |
(since 6.8) | value_type |
Public Functions
QVersionNumber() | |
QVersionNumber(QList<int> &&seg) | |
(since 6.8) | QVersionNumber(QSpan<const int> args) |
QVersionNumber(const QList<int> &seg) | |
QVersionNumber(int maj) | |
QVersionNumber(std::initializer_list<int> args) | |
QVersionNumber(int maj, int min) | |
QVersionNumber(int maj, int min, int mic) | |
(since 6.8) QVersionNumber::const_iterator | begin() const |
(since 6.8) QVersionNumber::const_iterator | cbegin() const |
(since 6.8) QVersionNumber::const_iterator | cend() const |
(since 6.8) QVersionNumber::const_iterator | constBegin() const |
(since 6.8) QVersionNumber::const_iterator | constEnd() const |
(since 6.8) QVersionNumber::const_reverse_iterator | crbegin() const |
(since 6.8) QVersionNumber::const_reverse_iterator | crend() const |
(since 6.8) QVersionNumber::const_iterator | end() const |
bool | isNormalized() const |
bool | isNull() const |
bool | isPrefixOf(const QVersionNumber &other) const |
int | majorVersion() const |
int | microVersion() const |
int | minorVersion() const |
QVersionNumber | normalized() const |
(since 6.8) QVersionNumber::const_reverse_iterator | rbegin() const |
(since 6.8) QVersionNumber::const_reverse_iterator | rend() const |
int | segmentAt(qsizetype index) const |
qsizetype | segmentCount() const |
QList<int> | segments() const |
QString | toString() const |
Static Public Members
QVersionNumber | commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2) |
int | compare(const QVersionNumber &v1, const QVersionNumber &v2) |
(since 6.4) QVersionNumber | fromString(QAnyStringView string, qsizetype *suffixIndex = nullptr) |
Related Non-Members
bool | operator!=(const QVersionNumber &lhs, const QVersionNumber &rhs) |
bool | operator<(const QVersionNumber &lhs, const QVersionNumber &rhs) |
QDataStream & | operator<<(QDataStream &out, const QVersionNumber &version) |
bool | operator<=(const QVersionNumber &lhs, const QVersionNumber &rhs) |
bool | operator==(const QVersionNumber &lhs, const QVersionNumber &rhs) |
bool | operator>(const QVersionNumber &lhs, const QVersionNumber &rhs) |
bool | operator>=(const QVersionNumber &lhs, const QVersionNumber &rhs) |
QDataStream & | operator>>(QDataStream &in, QVersionNumber &version) |
Detailed Description
QVersionNumber version(1, 2, 3); // 1.2.3
Member Type Documentation
[alias, since 6.8]
QVersionNumber::const_iterator
[alias, since 6.8]
QVersionNumber::const_reverse_iterator
Typedefs for an opaque class that implements a (reverse) random-access iterator over QVersionNumber segments.
Note: QVersionNumber does not support modifying segments in-place, so there is no mutable iterator.
This typedef was introduced in Qt 6.8.
[alias, since 6.8]
QVersionNumber::const_pointer
[alias, since 6.8]
QVersionNumber::const_reference
[alias, since 6.8]
QVersionNumber::difference_type
[alias, since 6.8]
QVersionNumber::pointer
[alias, since 6.8]
QVersionNumber::reference
[alias, since 6.8]
QVersionNumber::size_type
[alias, since 6.8]
QVersionNumber::value_type
Provided for STL-compatibility.
Note: QVersionNumber does not support modifying segments in-place, so reference and const_reference, as well as pointer and const_pointer are pairwise the same types.
This typedef was introduced in Qt 6.8.
Member Function Documentation
[noexcept, since 6.8]
QVersionNumber::const_iterator QVersionNumber::begin() const
[noexcept, since 6.8]
QVersionNumber::const_iterator QVersionNumber::cbegin() const
[noexcept, since 6.8]
QVersionNumber::const_iterator QVersionNumber::cend() const
[noexcept, since 6.8]
QVersionNumber::const_iterator QVersionNumber::constBegin() const
[noexcept, since 6.8]
QVersionNumber::const_iterator QVersionNumber::constEnd() const
[noexcept, since 6.8]
QVersionNumber::const_iterator QVersionNumber::end() const
[noexcept, since 6.8]
QVersionNumber::const_reverse_iterator QVersionNumber::crbegin() const
[noexcept, since 6.8]
QVersionNumber::const_reverse_iterator QVersionNumber::crend() const
[noexcept, since 6.8]
QVersionNumber::const_reverse_iterator QVersionNumber::rbegin() const
[noexcept, since 6.8]
QVersionNumber::const_reverse_iterator QVersionNumber::rend() const
Returns a const_iterator or const_reverse_iterator, respectively, pointing to the first or one past the last segment of this version number.
Note: QVersionNumber does not support modifying segments in-place, so there is no mutable iterator.
This function was introduced in Qt 6.8.
[noexcept]
QVersionNumber::QVersionNumber()
Produces a null version.
See also isNull().
[explicit]
QVersionNumber::QVersionNumber(QList<int> &&seg)
Move-constructs a version number from the list of numbers contained in seg.
[explicit, since 6.8]
QVersionNumber::QVersionNumber(QSpan<const int> args)
Constructs a version number from the span specified by args.
Note: In Qt versions prior to 6.8, QVersionNumber could only be constructed from QList, QVarLenthArray or std::initializer_list.
This function was introduced in Qt 6.8.
[explicit]
QVersionNumber::QVersionNumber(const QList<int> &seg)
Constructs a version number from the list of numbers contained in seg.
[explicit]
QVersionNumber::QVersionNumber(int maj)
Constructs a QVersionNumber consisting of just the major version number maj.
QVersionNumber::QVersionNumber(std::initializer_list<int> args)
Constructs a version number from the std::initializer_list specified by args.
[explicit]
QVersionNumber::QVersionNumber(int maj, int min)
Constructs a QVersionNumber consisting of the major and minor version numbers maj and min, respectively.
[explicit]
QVersionNumber::QVersionNumber(int maj, int min, int mic)
Constructs a QVersionNumber consisting of the major, minor, and micro version numbers maj, min and mic, respectively.
[static]
QVersionNumber QVersionNumber::commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2)
QVersionNumber QVersionNumber::commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2)
Returns a version number that is a parent version of both v1 and v2.
See also isPrefixOf().
[static noexcept]
int QVersionNumber::compare(const QVersionNumber &v1, const QVersionNumber &v2)
Compares v1 with v2 and returns an integer less than, equal to, or greater than zero, depending on whether v1 is less than, equal to, or greater than v2, respectively.
Comparisons are performed by comparing the segments of v1 and v2 starting at index 0 and working towards the end of the longer list.
QVersionNumber v1(1, 2); QVersionNumber v2(1, 2, 0); int compare = QVersionNumber::compare(v1, v2); // compare == -1
[static, since 6.4]
QVersionNumber QVersionNumber::fromString(QAnyStringView string, qsizetype *suffixIndex = nullptr)
Constructs a QVersionNumber from a specially formatted string of non-negative decimal numbers delimited by a period (.
).
Once the numerical segments have been parsed, the remainder of the string is considered to be the suffix string. The start index of that string will be stored in suffixIndex if it is not null.
QLatin1StringView string("5.4.0-alpha"); qsizetype suffixIndex; auto version = QVersionNumber::fromString(string, &suffixIndex); // version is 5.4.0 // suffixIndex is 5
Note: In versions prior to Qt 6.4, this function was overloaded for QString, QLatin1StringView and QStringView instead, and suffixIndex was an int*
.
This function was introduced in Qt 6.4.
See also isNull().
[noexcept]
bool QVersionNumber::isNormalized() const
Returns true
if the version number does not contain any trailing zeros, otherwise returns false
.
See also normalized().
[noexcept]
bool QVersionNumber::isNull() const
Returns true
if there are zero numerical segments, otherwise returns false
.
See also segments().
[noexcept]
bool QVersionNumber::isPrefixOf(const QVersionNumber &other) const
Returns true
if the current version number is contained in the other version number, otherwise returns false
.
QVersionNumber v1(5, 3); QVersionNumber v2(5, 3, 1); bool value = v1.isPrefixOf(v2); // true
See also commonPrefix().
[noexcept]
int QVersionNumber::majorVersion() const
Returns the major version number, that is, the first segment. This function is equivalent to segmentAt(0). If this QVersionNumber object is null, this function returns 0.
See also isNull() and segmentAt().
[noexcept]
int QVersionNumber::microVersion() const
Returns the micro version number, that is, the third segment. This function is equivalent to segmentAt(2). If this QVersionNumber object does not contain a micro number, this function returns 0.
See also isNull() and segmentAt().
[noexcept]
int QVersionNumber::minorVersion() const
Returns the minor version number, that is, the second segment. This function is equivalent to segmentAt(1). If this QVersionNumber object does not contain a minor number, this function returns 0.
See also isNull() and segmentAt().
QVersionNumber QVersionNumber::normalized() const
Returns an equivalent version number but with all trailing zeros removed.
To check if two numbers are equivalent, use normalized() on both version numbers before performing the compare.
QVersionNumber v1(5, 4); QVersionNumber v2(5, 4, 0); bool equivalent = v1.normalized() == v2.normalized(); bool equal = v1 == v2; // equivalent is true // equal is false
[noexcept]
int QVersionNumber::segmentAt(qsizetype index) const
Returns the segment value at index. If the index does not exist, returns 0.
See also segments() and segmentCount().
[noexcept]
qsizetype QVersionNumber::segmentCount() const
Returns the number of integers stored in segments().
See also segments().
QList<int> QVersionNumber::segments() const
Returns all of the numerical segments.
See also majorVersion(), minorVersion(), and microVersion().
QString QVersionNumber::toString() const
Returns a string with all of the segments delimited by a period (.
).
See also majorVersion(), minorVersion(), microVersion(), and segments().
Related Non-Members
[noexcept]
bool operator!=(const QVersionNumber &lhs, const QVersionNumber &rhs)
Returns true
if lhs is not equal to rhs; otherwise returns false
.
See also QVersionNumber::compare().
[noexcept]
bool operator<(const QVersionNumber &lhs, const QVersionNumber &rhs)
Returns true
if lhs is less than rhs; otherwise returns false
.
See also QVersionNumber::compare().
QDataStream &operator<<(QDataStream &out, const QVersionNumber &version)
Writes the version number version to stream out.
Note that this has nothing to do with QDataStream::version().
[noexcept]
bool operator<=(const QVersionNumber &lhs, const QVersionNumber &rhs)
Returns true
if lhs is less than or equal to rhs; otherwise returns false
.
See also QVersionNumber::compare().
[noexcept]
bool operator==(const QVersionNumber &lhs, const QVersionNumber &rhs)
Returns true
if lhs is equal to rhs; otherwise returns false
.
See also QVersionNumber::compare().
[noexcept]
bool operator>(const QVersionNumber &lhs, const QVersionNumber &rhs)
Returns true
if lhs is greater than rhs; otherwise returns false
.
See also QVersionNumber::compare().
[noexcept]
bool operator>=(const QVersionNumber &lhs, const QVersionNumber &rhs)
Returns true
if lhs is greater than or equal to rhs; otherwise returns false
.
See also QVersionNumber::compare().
QDataStream &operator>>(QDataStream &in, QVersionNumber &version)
Reads a version number from stream in and stores it in version.
Note that this has nothing to do with QDataStream::version().