Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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=0)
 \qhashold{QHash}
 

Related Symbols

(Note that these are not member symbols.)

QDataStreamoperator<< (QDataStream &out, const QVersionNumber &version)
 Writes the version number version to stream out.
 

Detailed Description

\inmodule QtCore

Since
5.6

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

\compares strong

QVersionNumber version(1, 2, 3); // 1.2.3

Definition at line 31 of file qversionnumber.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 271 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 280 of file qversionnumber.h.

◆ const_reference

Definition at line 278 of file qversionnumber.h.

◆ 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 272 of file qversionnumber.h.

◆ difference_type

using QVersionNumber::difference_type = It::difference_type

Definition at line 275 of file qversionnumber.h.

◆ pointer

Definition at line 279 of file qversionnumber.h.

◆ reference

using QVersionNumber::reference = It::reference

Definition at line 277 of file qversionnumber.h.

◆ size_type

using QVersionNumber::size_type = It::size_type

Definition at line 276 of file qversionnumber.h.

◆ value_type

using QVersionNumber::value_type = It::value_type

Definition at line 274 of file qversionnumber.h.

Constructor & Destructor Documentation

◆ QVersionNumber() [1/8]

QVersionNumber::QVersionNumber ( )
inlinenoexcept

Produces a null version.

See also
isNull()

Definition at line 282 of file qversionnumber.h.

References QVersionNumber().

Referenced by QVersionNumber(), and CPP::colorRoleVersionAdded().

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

◆ QVersionNumber() [2/8]

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

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

Definition at line 286 of file qversionnumber.h.

◆ QVersionNumber() [3/8]

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

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

Definition at line 291 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 293 of file qversionnumber.h.

References QVersionNumber().

Referenced by QVersionNumber().

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

◆ 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 297 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 301 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 304 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 307 of file qversionnumber.h.

Member Function Documentation

◆ begin()

const_iterator QVersionNumber::begin ( ) const
inlinenodiscardnoexcept

Definition at line 335 of file qversionnumber.h.

Referenced by cbegin(), and constBegin().

+ Here is the caller graph for this function:

◆ cbegin()

const_iterator QVersionNumber::cbegin ( ) const
inlinenodiscardnoexcept

Definition at line 337 of file qversionnumber.h.

References begin().

+ Here is the call graph for this function:

◆ cend()

const_iterator QVersionNumber::cend ( ) const
inlinenodiscardnoexcept

Definition at line 338 of file qversionnumber.h.

References end().

+ Here is the call graph for this function:

◆ commonPrefix()

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

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.

◆ compare()

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

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

Definition at line 283 of file qversionnumber.cpp.

◆ constBegin()

const_iterator QVersionNumber::constBegin ( ) const
inlinenodiscardnoexcept

Definition at line 345 of file qversionnumber.h.

References begin().

+ Here is the call graph for this function:

◆ constEnd()

const_iterator QVersionNumber::constEnd ( ) const
inlinenodiscardnoexcept
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 346 of file qversionnumber.h.

References end().

+ Here is the call graph for this function:

◆ crbegin()

const_reverse_iterator QVersionNumber::crbegin ( ) const
inlinenodiscardnoexcept

Definition at line 342 of file qversionnumber.h.

◆ crend()

const_reverse_iterator QVersionNumber::crend ( ) const
inlinenodiscardnoexcept

Definition at line 343 of file qversionnumber.h.

◆ end()

const_iterator QVersionNumber::end ( ) const
inlinenodiscardnoexcept

Definition at line 336 of file qversionnumber.h.

Referenced by cend(), and constEnd().

+ Here is the caller graph for this function:

◆ fromString()

QVersionNumber QVersionNumber::fromString ( QAnyStringView string,
qsizetype * suffixIndex = nullptr )
staticnodiscard
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.

◆ isNormalized()

bool QVersionNumber::isNormalized ( ) const
inlinenodiscardnoexcept

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

See also
normalized()

Definition at line 313 of file qversionnumber.h.

◆ isNull()

bool QVersionNumber::isNull ( ) const
inlinenodiscardnoexcept

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

See also
segments()

Definition at line 310 of file qversionnumber.h.

◆ isPrefixOf()

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

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

Definition at line 259 of file qversionnumber.cpp.

◆ majorVersion()

int QVersionNumber::majorVersion ( ) const
inlinenodiscardnoexcept

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 316 of file qversionnumber.h.

◆ microVersion()

int QVersionNumber::microVersion ( ) const
inlinenodiscardnoexcept

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 322 of file qversionnumber.h.

◆ minorVersion()

int QVersionNumber::minorVersion ( ) const
inlinenodiscardnoexcept

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 319 of file qversionnumber.h.

◆ normalized()

QVersionNumber QVersionNumber::normalized ( ) const
nodiscard

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

Definition at line 237 of file qversionnumber.cpp.

◆ rbegin()

const_reverse_iterator QVersionNumber::rbegin ( ) const
inlinenodiscardnoexcept

Definition at line 340 of file qversionnumber.h.

◆ rend()

const_reverse_iterator QVersionNumber::rend ( ) const
inlinenodiscardnoexcept

Definition at line 341 of file qversionnumber.h.

◆ segmentAt()

int QVersionNumber::segmentAt ( qsizetype index) const
inlinenodiscardnoexcept

Returns the segment value at index.

If the index does not exist, returns 0.

See also
segments(), segmentCount()

Definition at line 329 of file qversionnumber.h.

◆ segmentCount()

qsizetype QVersionNumber::segmentCount ( ) const
inlinenodiscardnoexcept

Returns the number of integers stored in segments().

See also
segments()

Definition at line 332 of file qversionnumber.h.

◆ segments()

QList< int > QVersionNumber::segments ( ) const
nodiscard

Returns all of the numerical segments.

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

Definition at line 149 of file qversionnumber.cpp.

◆ toString()

QString QVersionNumber::toString ( ) const
nodiscard

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.

Friends And Related Symbol Documentation

◆ comparesEqual

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

Definition at line 384 of file qversionnumber.h.

◆ compareThreeWay

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

Definition at line 389 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().

◆ operator>>

Q_CORE_EXPORT 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 = 0 )
friend

\qhashold{QHash}

Since
5.6

Definition at line 577 of file qversionnumber.cpp.


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