Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QVersionNumber Class Reference

\inmodule QtCore More...

#include <qversionnumber.h>

+ Collaboration diagram for QVersionNumber:

Public Member Functions

 QVersionNumber () noexcept
 Produces a null version.
 
 QVersionNumber (const QList< int > &seg)
 Constructs a version number from the list of numbers contained in seg.
 
 QVersionNumber (QList< int > &&seg)
 Move-constructs a version number from the list of numbers contained in seg.
 
 QVersionNumber (std::initializer_list< int > args)
 Construct a version number from the std::initializer_list specified by args.
 
template<qsizetype N>
 QVersionNumber (const QVarLengthArray< int, N > &sec)
 
 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().
 
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 operator> (const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
 Returns true if lhs is greater than rhs; otherwise returns false.
 
bool operator>= (const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
 Returns true if lhs is greater than or equal to rhs; otherwise returns false.
 
bool operator< (const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
 Returns true if lhs is less than rhs; otherwise returns false.
 
bool operator<= (const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
 Returns true if lhs is less than or equal to rhs; otherwise returns false.
 
bool operator== (const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
 Returns true if lhs is equal to rhs; otherwise returns false.
 
bool operator!= (const QVersionNumber &lhs, const QVersionNumber &rhs) noexcept
 Returns true if lhs is not equal to rhs; otherwise returns false.
 
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.

QVersionNumber version(1, 2, 3); // 1.2.3
\inmodule QtCore

Definition at line 26 of file qversionnumber.h.

Constructor & Destructor Documentation

◆ QVersionNumber() [1/8]

QVersionNumber::QVersionNumber ( )
inlinenoexcept

Produces a null version.

See also
isNull()

Definition at line 192 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 195 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.

This constructor is only enabled if the compiler supports C++11 move semantics.

Definition at line 199 of file qversionnumber.h.

◆ QVersionNumber() [4/8]

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

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

This constructor is only enabled if the compiler supports C++11 initializer lists.

Definition at line 201 of file qversionnumber.h.

◆ QVersionNumber() [5/8]

template<qsizetype N>
template< qsizetype N > QVersionNumber::QVersionNumber ( const QVarLengthArray< int, N > &  seg)
inlineexplicit
Since
6.4

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

Definition at line 206 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 210 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 213 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 216 of file qversionnumber.h.

Member Function Documentation

◆ 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 285 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
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,...
GLint GLfloat GLfloat GLfloat v2
GLint GLfloat GLfloat v1
#define v1

Definition at line 236 of file qversionnumber.cpp.

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

Referenced by Object::equalityExample().

+ 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
static Q_CORE_EXPORT QVersionNumber fromString(QAnyStringView string, qsizetype *suffixIndex=nullptr)
GLsizei const GLchar *const * string
[0]
Definition qopenglext.h:694
ptrdiff_t qsizetype
Definition qtypes.h:70
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 442 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 222 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 219 of file qversionnumber.h.

References segmentCount().

Referenced by bluetoothdVersion(), QWindowsDirect2DIntegration::create(), 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
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
See also
commonPrefix()

Definition at line 212 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 225 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 231 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 228 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
static bool equal(const QChar *a, int l, const char *b)
Definition qurlidna.cpp:338

Definition at line 190 of file qversionnumber.cpp.

References i.

Referenced by qRequireVersion().

+ 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 238 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 241 of file qversionnumber.h.

Referenced by 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 151 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 363 of file qversionnumber.cpp.

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

Referenced by QWindowsDirect2DIntegration::create(), operator<<(), 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

◆ operator!=

bool QVersionNumber::operator!= ( const QVersionNumber lhs,
const QVersionNumber rhs 
)
friend

Returns true if lhs is not equal to rhs; otherwise returns false.

See also
QVersionNumber::compare()

Definition at line 294 of file qversionnumber.h.

◆ operator<

bool QVersionNumber::operator< ( const QVersionNumber lhs,
const QVersionNumber rhs 
)
friend

Returns true if lhs is less than rhs; otherwise returns false.

See also
QVersionNumber::compare()

Definition at line 285 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 493 of file qversionnumber.cpp.

References out, and segments().

+ Here is the call graph for this function:

◆ operator<=

bool QVersionNumber::operator<= ( const QVersionNumber lhs,
const QVersionNumber rhs 
)
friend

Returns true if lhs is less than or equal to rhs; otherwise returns false.

See also
QVersionNumber::compare()

Definition at line 288 of file qversionnumber.h.

◆ operator==

bool QVersionNumber::operator== ( const QVersionNumber lhs,
const QVersionNumber rhs 
)
friend

Returns true if lhs is equal to rhs; otherwise returns false.

See also
QVersionNumber::compare()

Definition at line 291 of file qversionnumber.h.

◆ operator>

bool QVersionNumber::operator> ( const QVersionNumber lhs,
const QVersionNumber rhs 
)
friend

Returns true if lhs is greater than rhs; otherwise returns false.

See also
QVersionNumber::compare()

Definition at line 279 of file qversionnumber.h.

◆ operator>=

bool QVersionNumber::operator>= ( const QVersionNumber lhs,
const QVersionNumber rhs 
)
friend

Returns true if lhs is greater than or equal to rhs; otherwise returns false.

See also
QVersionNumber::compare()

Definition at line 282 of file qversionnumber.h.

◆ 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 507 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 507 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: