Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QVersionNumber Class Reference

\inmodule QtCore More...

#include <qversionnumber.h>

+ Collaboration diagram for QVersionNumber:

Public Types

using const_iterator = It
 
using const_reverse_iterator = std::reverse_iterator<const_iterator>
 
using value_type = It::value_type
 
using difference_type = It::difference_type
 
using size_type = It::size_type
 
using reference = It::reference
 
using const_reference = reference
 
using pointer = It::pointer
 
using const_pointer = pointer
 

Public Member Functions

 QVersionNumber () noexcept
 Produces a null version.
 
Q_WEAK_OVERLOAD QVersionNumber (const QList< int > &seg)
 Constructs a version number from the list of numbers contained in seg.
 
Q_WEAK_OVERLOAD QVersionNumber (QList< int > &&seg)
 Move-constructs a version number from the list of numbers contained in seg.
 
 QVersionNumber (std::initializer_list< int > args)
 Constructs a version number from the std::initializer_list specified by args.
 
 QVersionNumber (QSpan< const int > args)
 
 QVersionNumber (int maj)
 Constructs a QVersionNumber consisting of just the major version number maj.
 
 QVersionNumber (int maj, int min)
 Constructs a QVersionNumber consisting of the major and minor version numbers maj and min, respectively.
 
 QVersionNumber (int maj, int min, int mic)
 Constructs a QVersionNumber consisting of the major, minor, and micro version numbers maj, min and mic, respectively.
 
bool isNull () const noexcept
 Returns true if there are zero numerical segments, otherwise returns false.
 
bool isNormalized () const noexcept
 Returns true if the version number does not contain any trailing zeros, otherwise returns false.
 
int majorVersion () const noexcept
 Returns the major version number, that is, the first segment.
 
int minorVersion () const noexcept
 Returns the minor version number, that is, the second segment.
 
int microVersion () const noexcept
 Returns the micro version number, that is, the third segment.
 
Q_CORE_EXPORT QVersionNumber normalized () const
 Returns an equivalent version number but with all trailing zeros removed.
 
Q_CORE_EXPORT QList< int > segments () const
 Returns all of the numerical segments.
 
int segmentAt (qsizetype index) const noexcept
 Returns the segment value at index.
 
qsizetype segmentCount () const noexcept
 Returns the number of integers stored in segments().
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
const_reverse_iterator rbegin () const noexcept
 
const_reverse_iterator rend () const noexcept
 
const_reverse_iterator crbegin () const noexcept
 
const_reverse_iterator crend () const noexcept
 
const_iterator constBegin () const noexcept
 
const_iterator constEnd () const noexcept
 
Q_CORE_EXPORT bool isPrefixOf (const QVersionNumber &other) const noexcept
 Returns true if the current version number is contained in the other version number, otherwise returns false.
 
Q_CORE_EXPORT QString toString () const
 Returns a string with all of the segments delimited by a period ({.}).
 

Static Public Member Functions

static Q_CORE_EXPORT int compare (const QVersionNumber &v1, const QVersionNumber &v2) noexcept
 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.
 
static Q_CORE_EXPORT QVersionNumber commonPrefix (const QVersionNumber &v1, const QVersionNumber &v2)
 QVersionNumber QVersionNumber::commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2)
 
static Q_CORE_EXPORT QVersionNumber fromString (QAnyStringView string, qsizetype *suffixIndex=nullptr)
 

Friends

bool comparesEqual (const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
 
Qt::strong_ordering compareThreeWay (const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
 
Q_CORE_EXPORT QDataStreamoperator>> (QDataStream &in, QVersionNumber &version)
 Reads a version number from stream in and stores it in version.
 
Q_CORE_EXPORT size_t qHash (const QVersionNumber &key, size_t seed)
 

Related Symbols

(Note that these are not member symbols.)

QDataStreamoperator<< (QDataStream &out, const QVersionNumber &version)
 Writes the version number version to stream out.
 
QDataStreamoperator>> (QDataStream &in, QVersionNumber &version)
 Reads a version number from stream in and stores it in version.
 

Detailed Description

\inmodule QtCore

Since
5.6

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

\compares strong

Definition at line 31 of file qversionnumber.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 247 of file qversionnumber.h.

◆ const_pointer

Since
6.8

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.

Definition at line 256 of file qversionnumber.h.

◆ const_reference

◆ const_reverse_iterator

Since
6.8

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.

Definition at line 248 of file qversionnumber.h.

◆ difference_type

QVersionNumber::difference_type = It::difference_type

Definition at line 251 of file qversionnumber.h.

◆ pointer

◆ reference

QVersionNumber::reference = It::reference

Definition at line 253 of file qversionnumber.h.

◆ size_type

QVersionNumber::size_type = It::size_type

Definition at line 252 of file qversionnumber.h.

◆ value_type

QVersionNumber::value_type = It::value_type

Definition at line 250 of file qversionnumber.h.

Constructor & Destructor Documentation

◆ QVersionNumber() [1/8]

QVersionNumber::QVersionNumber ( )
inlinenoexcept

Produces a null version.

See also
isNull()

Definition at line 258 of file qversionnumber.h.

Referenced by commonPrefix().

+ Here is the caller graph for this function:

◆ QVersionNumber() [2/8]

QVersionNumber::QVersionNumber ( const QList< int > & seg)
inlineexplicit

Constructs a version number from the list of numbers contained in seg.

Definition at line 262 of file qversionnumber.h.

◆ QVersionNumber() [3/8]

QVersionNumber::QVersionNumber ( QList< int > && seg)
inlineexplicit

Move-constructs a version number from the list of numbers contained in seg.

Definition at line 267 of file qversionnumber.h.

◆ QVersionNumber() [4/8]

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

Constructs a version number from the std::initializer_list specified by args.

Definition at line 269 of file qversionnumber.h.

◆ QVersionNumber() [5/8]

QVersionNumber::QVersionNumber ( QSpan< const int > args)
inlineexplicit
Since
6.8

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.

Definition at line 273 of file qversionnumber.h.

◆ QVersionNumber() [6/8]

QVersionNumber::QVersionNumber ( int maj)
inlineexplicit

Constructs a QVersionNumber consisting of just the major version number maj.

Definition at line 277 of file qversionnumber.h.

◆ QVersionNumber() [7/8]

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

Constructs a QVersionNumber consisting of the major and minor version numbers maj and min, respectively.

Definition at line 280 of file qversionnumber.h.

◆ QVersionNumber() [8/8]

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

Constructs a QVersionNumber consisting of the major, minor, and micro version numbers maj, min and mic, respectively.

Definition at line 283 of file qversionnumber.h.

Member Function Documentation

◆ begin()

QVersionNumber::begin ( ) const
inlinenoexcept

Definition at line 311 of file qversionnumber.h.

Referenced by cbegin(), constBegin(), end(), and rend().

+ Here is the caller graph for this function:

◆ cbegin()

QVersionNumber::cbegin ( ) const
inlinenoexcept

Definition at line 313 of file qversionnumber.h.

References begin().

+ Here is the call graph for this function:

◆ cend()

QVersionNumber::cend ( ) const
inlinenoexcept

Definition at line 314 of file qversionnumber.h.

References end().

+ Here is the call graph for this function:

◆ commonPrefix()

QVersionNumber QVersionNumber::commonPrefix ( const QVersionNumber & v1,
const QVersionNumber & v2 )
static

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()

Definition at line 332 of file qversionnumber.cpp.

References QVersionNumber(), i, and qMin().

+ Here is the call graph for this function:

◆ compare()

int QVersionNumber::compare ( const QVersionNumber & v1,
const QVersionNumber & v2 )
staticnoexcept

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 v2(1, 2, 0);
int compare = QVersionNumber::compare(v1, v2); // compare == -1

Definition at line 283 of file qversionnumber.cpp.

References i, Q_LIKELY, qint8, and qMin().

Referenced by Object::equalityExample(), and init_platform().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ constBegin()

QVersionNumber::constBegin ( ) const
inlinenoexcept

Definition at line 321 of file qversionnumber.h.

References begin().

+ Here is the call graph for this function:

◆ constEnd()

QVersionNumber::constEnd ( ) const
inlinenoexcept
Since
6.8

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.

Definition at line 322 of file qversionnumber.h.

References end().

+ Here is the call graph for this function:

◆ crbegin()

QVersionNumber::crbegin ( ) const
inlinenoexcept

Definition at line 318 of file qversionnumber.h.

References rbegin().

+ Here is the call graph for this function:

◆ crend()

QVersionNumber::crend ( ) const
inlinenoexcept

Definition at line 319 of file qversionnumber.h.

References rend().

+ Here is the call graph for this function:

◆ end()

QVersionNumber::end ( ) const
inlinenoexcept

Definition at line 312 of file qversionnumber.h.

References begin(), and segmentCount().

Referenced by cend(), constEnd(), and rbegin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromString()

QVersionNumber QVersionNumber::fromString ( QAnyStringView string,
qsizetype * suffixIndex = nullptr )
static
Since
6.4

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*}.
See also
isNull()

Definition at line 489 of file qversionnumber.cpp.

References from_string().

Referenced by bluetoothdVersion(), findDependencyInfo(), and qRequireVersion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isNormalized()

bool QVersionNumber::isNormalized ( ) const
inlinenoexcept

Returns true if the version number does not contain any trailing zeros, otherwise returns false.

See also
normalized()

Definition at line 289 of file qversionnumber.h.

References isNull(), segmentAt(), and segmentCount().

+ Here is the call graph for this function:

◆ isNull()

bool QVersionNumber::isNull ( ) const
inlinenoexcept

Returns true if there are zero numerical segments, otherwise returns false.

See also
segments()

Definition at line 286 of file qversionnumber.h.

References segmentCount().

Referenced by QBasicPlatformVulkanInstance::initInstance(), isNormalized(), and matches().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isPrefixOf()

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

Returns true if the current version number is contained in the other version number, otherwise returns false.

QVersionNumber v2(5, 3, 1);
bool value = v1.isPrefixOf(v2); // true
See also
commonPrefix()

Definition at line 259 of file qversionnumber.cpp.

References i, other(), and segmentCount().

+ Here is the call graph for this function:

◆ majorVersion()

int QVersionNumber::majorVersion ( ) const
inlinenoexcept

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(), segmentAt()

Definition at line 292 of file qversionnumber.h.

References segmentAt().

Referenced by QBasicPlatformVulkanInstance::initInstance().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ microVersion()

int QVersionNumber::microVersion ( ) const
inlinenoexcept

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(), segmentAt()

Definition at line 298 of file qversionnumber.h.

References segmentAt().

Referenced by QBasicPlatformVulkanInstance::initInstance().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minorVersion()

int QVersionNumber::minorVersion ( ) const
inlinenoexcept

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(), segmentAt()

Definition at line 295 of file qversionnumber.h.

References segmentAt().

Referenced by QBasicPlatformVulkanInstance::initInstance().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ normalized()

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 v2(5, 4, 0);
bool equivalent = v1.normalized() == v2.normalized();
bool equal = v1 == v2;
// equivalent is true
// equal is false

Definition at line 237 of file qversionnumber.cpp.

References i.

◆ rbegin()

QVersionNumber::rbegin ( ) const
inlinenoexcept

Definition at line 316 of file qversionnumber.h.

References end().

Referenced by crbegin().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rend()

QVersionNumber::rend ( ) const
inlinenoexcept

Definition at line 317 of file qversionnumber.h.

References begin().

Referenced by crend().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ segmentAt()

int QVersionNumber::segmentAt ( qsizetype index) const
inlinenoexcept

Returns the segment value at index.

If the index does not exist, returns 0.

See also
segments(), segmentCount()

Definition at line 305 of file qversionnumber.h.

Referenced by isNormalized(), majorVersion(), microVersion(), minorVersion(), toString(), and GpuDescription::toVariant().

+ Here is the caller graph for this function:

◆ segmentCount()

qsizetype QVersionNumber::segmentCount ( ) const
inlinenoexcept

Returns the number of integers stored in segments().

See also
segments()

Definition at line 308 of file qversionnumber.h.

Referenced by end(), isNormalized(), isNull(), and toString().

+ Here is the caller graph for this function:

◆ segments()

QList< int > QVersionNumber::segments ( ) const

Returns all of the numerical segments.

See also
majorVersion(), minorVersion(), microVersion()

Definition at line 149 of file qversionnumber.cpp.

References i, and segmentCount().

Referenced by operator<<().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toString()

QString QVersionNumber::toString ( ) const

Returns a string with all of the segments delimited by a period ({.}).

See also
majorVersion(), minorVersion(), microVersion(), segments()

Definition at line 410 of file qversionnumber.cpp.

References i, QString::number(), qMax(), QString::reserve(), segmentAt(), and segmentCount().

Referenced by operator<<(), QOpenXRRuntimeInfo::runtimeVersion(), GpuDescription::toString(), and GpuDescription::toVariant().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ comparesEqual

bool comparesEqual ( const QVersionNumber & lhs,
const QVersionNumber & rhs )
friend

Definition at line 360 of file qversionnumber.h.

◆ compareThreeWay

Qt::strong_ordering compareThreeWay ( const QVersionNumber & lhs,
const QVersionNumber & rhs )
friend

Definition at line 365 of file qversionnumber.h.

◆ operator<<()

QDataStream & operator<< ( QDataStream & out,
const QVersionNumber & version )
related

Writes the version number version to stream out.

Note that this has nothing to do with QDataStream::version().

Definition at line 540 of file qversionnumber.cpp.

References out, and segments().

+ Here is the call graph for this function:

◆ operator>>() [1/2]

QDataStream & operator>> ( QDataStream & in,
QVersionNumber & version )
related

Reads a version number from stream in and stores it in version.

Note that this has nothing to do with QDataStream::version().

Definition at line 554 of file qversionnumber.cpp.

◆ operator>> [2/2]

QDataStream & operator>> ( QDataStream & in,
QVersionNumber & version )
friend

Reads a version number from stream in and stores it in version.

Note that this has nothing to do with QDataStream::version().

Definition at line 554 of file qversionnumber.cpp.

◆ qHash

Q_CORE_EXPORT size_t qHash ( const QVersionNumber & key,
size_t seed )
friend

The documentation for this class was generated from the following files: