CopperSpice API  1.7.2
QVersionNumber Class Reference

Contains a version number with an arbitrary number of segments. More...

Public Methods

 QVersionNumber ()
 
 QVersionNumber (const QVector< int > &seg)
 
 QVersionNumber (int maj)
 
 QVersionNumber (int maj, int min)
 
 QVersionNumber (int maj, int min, int mic)
 
 QVersionNumber (QVector< int > &&seg)
 
 QVersionNumber (std::initializer_list< int > args)
 
bool isNormalized () const
 
bool isNull () const
 
bool isPrefixOf (const QVersionNumber &other) const
 
int majorVersion () const
 
int microVersion () const
 
int minorVersion () const
 
QVersionNumber normalized () const
 
int segmentAt (int index) const
 
int segmentCount () const
 
QVector< int > segments () const
 
QString toString () const
 

Static Public Methods

static QVersionNumber commonPrefix (const QVersionNumber &v1, const QVersionNumber &v2)
 
static int compare (const QVersionNumber &v1, const QVersionNumber &v2)
 
static QVersionNumber fromString (const QString &string, int *suffixIndex=nullptr)
 

Friends

QDataStreamoperator>> (QDataStream &in, QVersionNumber &version)
 

Related Functions

These are not member functions

bool operator!= (const QVersionNumber &lhs, const QVersionNumber &rhs)
 
QDataStreamoperator<< (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)
 

Detailed Description

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

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

Constructor & Destructor Documentation

QVersionNumber::QVersionNumber ( )
inline

Produces a null version.

See also
isNull()
QVersionNumber::QVersionNumber ( const QVector< int > &  seg)
inlineexplicit

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

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

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

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

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

QVersionNumber::QVersionNumber ( int  maj)
inlineexplicit

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

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

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

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.

Method Documentation

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

Returns a version number that is a parent version of both v1 and v2.

See also
isPrefixOf()
int QVersionNumber::compare ( const QVersionNumber &  v1,
const QVersionNumber &  v2 
)
static

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
QVersionNumber QVersionNumber::fromString ( const QString string,
int *  suffixIndex = nullptr 
)
static

Constructs a QVersionNumber from a specially formatted string of non-negative decimal numbers delimited by '.'.

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.

QString string("1.6.3-alpha");
int suffixIndex;
QVersionNumber version = QVersionNumber::fromString(string, &suffixIndex);
// version is 1.6.3
// suffixIndex is 5
See also
isNull()
bool QVersionNumber::isNormalized ( ) const
inline

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

See also
normalized()
bool QVersionNumber::isNull ( ) const
inline

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

See also
segments()
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()
int QVersionNumber::majorVersion ( ) const
inline

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()
int QVersionNumber::microVersion ( ) const
inline

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()
int QVersionNumber::minorVersion ( ) const
inline

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()
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(1, 6);
QVersionNumber v2(1, 6, 0);
bool equivalent = v1.normalized() == v2.normalized(); // equivalent is true
bool equal = v1 == v2; // equal is false
int QVersionNumber::segmentAt ( int  index) const
inline

Returns the segment value at index. If the index does not exist, returns 0.

See also
segments(), segmentCount()
int QVersionNumber::segmentCount ( ) const
inline

Returns the number of integers stored in segments().

See also
segments()
QVector< int > QVersionNumber::segments ( ) const

Returns all of the numerical segments.

See also
majorVersion(), minorVersion(), microVersion()
QString QVersionNumber::toString ( ) const

Returns a string with all of the segments delimited by a period.

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

Friends And Related Function Documentation

bool operator!= ( const QVersionNumber &  lhs,
const QVersionNumber &  rhs 
)
related

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

See also
QVersionNumber::compare()
QDataStream & operator<< ( QDataStream out,
const QVersionNumber &  version 
)
related

Writes the version numberversion to stream out.

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

bool operator<= ( const QVersionNumber &  lhs,
const QVersionNumber &  rhs 
)
related

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

See also
QVersionNumber::compare()
bool operator== ( const QVersionNumber &  lhs,
const QVersionNumber &  rhs 
)
related

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

See also
QVersionNumber::compare()
bool operator> ( const QVersionNumber &  lhs,
const QVersionNumber &  rhs 
)
related

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

See also
QVersionNumber::compare()
bool operator>= ( const QVersionNumber &  lhs,
const QVersionNumber &  rhs 
)
related

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

See also
QVersionNumber::compare()
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().