QPair 类

The QPair class is a template class that stores a pair of items. 更多...

头: #include <QPair>

公共类型

typedef first_type
typedef second_type

公共函数

QPair ()
QPair (const T1 & value1 , const T2 & value2 )
QPair<T1, T2> & operator= (const QPair<T1, T2> & other )

公共变量

T1 first
T2 second
QPair<T1, T2> qMakePair (const T1 & value1 , const T2 & value2 )
bool operator!= (const QPair<T1, T2> & p1 , const QPair<T1, T2> & p2 )
bool operator< (const QPair<T1, T2> & p1 , const QPair<T1, T2> & p2 )
QDataStream & operator<< (QDataStream & out , const QPair<T1, T2> & pair )
bool operator<= (const QPair<T1, T2> & p1 , const QPair<T1, T2> & p2 )
bool operator== (const QPair<T1, T2> & p1 , const QPair<T1, T2> & p2 )
bool operator> (const QPair<T1, T2> & p1 , const QPair<T1, T2> & p2 )
bool operator>= (const QPair<T1, T2> & p1 , const QPair<T1, T2> & p2 )
QDataStream & operator>> (QDataStream & in , QPair<T1, T2> & pair )

详细描述

The QPair class is a template class that stores a pair of items.

QPair <T1, T2> can be used in your application if the STL pair type is not available. It stores one value of type T1 and one value of type T2. It can be used as a return value for a function that needs to return two values, or as the value type of a generic container .

Here's an example of a QPair that stores one QString and one double 值:

QPair<QString, double> pair;
					

The components are accessible as public data members called first and second 。例如:

pair.first = "pi";
pair.second = 3.14159265358979323846;
					

QPair 's template data types (T1 and T2) must be 可赋值数据类型 。例如,无法存储 QWidget 作为值;取而代之,存储 QWidget *. A few functions have additional requirements; these requirements are documented on a per-function basis.

另请参阅 容器类 .

成员类型文档编制

typedef QPair:: first_type

The type of the first element in the pair (T1).

另请参阅 first .

typedef QPair:: second_type

The type of the second element in the pair (T2).

另请参阅 second .

成员函数文档编制

QPair:: QPair ()

Constructs an empty pair. The 第一 and second elements are initialized with default-constructed values .

QPair:: QPair (const T1 & value1 , const T2 & value2 )

Constructs a pair and initializes the 第一 element with value1 second element with value2 .

另请参阅 qMakePair ().

QPair < T1 , T2 > & QPair:: operator= (const QPair < T1 , T2 > & other )

赋值 other to this pair.

成员变量文档编制

T1 QPair:: first

The first element in the pair.

T2 QPair:: second

The second element in the pair.

相关非成员

QPair < T1 , T2 > qMakePair (const T1 & value1 , const T2 & value2 )

返回 QPair <T1, T2> that contains value1 and value2 。范例:

QList<QPair<int, double> > list;
list.append(qMakePair(66, 3.14159));
					

这相当于 QPair <T1, T2>( value1 , value2 ), but usually requires less typing.

bool operator!= (const QPair < T1 , T2 > & p1 , const QPair < T1 , T2 > & p2 )

返回 true 若 p1 不等于 p2 ; otherwise returns false. Two pairs compare as not equal if their 第一 data members are not equal or if their second data members are not equal.

This function requires the T1 and T2 types to have an implementation of operator==() .

bool operator< (const QPair < T1 , T2 > & p1 , const QPair < T1 , T2 > & p2 )

返回 true 若 p1 小于 p2 ; otherwise returns false. The comparison is done on the 第一 members of p1 and p2 ; if they compare equal, the second members are compared to break the tie.

This function requires the T1 and T2 types to have an implementation of operator<() .

QDataStream & operator<< ( QDataStream & out , const QPair < T1 , T2 > & pair )

Writes the pair pair 到流 out .

This function requires the T1 and T2 types to implement operator<<() .

另请参阅 序列化 Qt 数据类型 .

bool operator<= (const QPair < T1 , T2 > & p1 , const QPair < T1 , T2 > & p2 )

返回 true 若 p1 <= p2 ; otherwise returns false. The comparison is done on the 第一 members of p1 and p2 ; if they compare equal, the second members are compared to break the tie.

This function requires the T1 and T2 types to have an implementation of operator<() .

bool operator== (const QPair < T1 , T2 > & p1 , const QPair < T1 , T2 > & p2 )

返回 true 若 p1 等于 p2 ; otherwise returns false. Two pairs compare equal if their 第一 data members compare equal and if their second data members compare equal.

This function requires the T1 and T2 types to have an implementation of operator==() .

bool operator> (const QPair < T1 , T2 > & p1 , const QPair < T1 , T2 > & p2 )

返回 true 若 p1 大于 p2 ; otherwise returns false. The comparison is done on the 第一 members of p1 and p2 ; if they compare equal, the second members are compared to break the tie.

This function requires the T1 and T2 types to have an implementation of operator<() .

bool operator>= (const QPair < T1 , T2 > & p1 , const QPair < T1 , T2 > & p2 )

返回 true 若 p1 >= p2 ; otherwise returns false. The comparison is done on the 第一 members of p1 and p2 ; if they compare equal, the second members are compared to break the tie.

This function requires the T1 and T2 types to have an implementation of operator<() .

QDataStream & operator>> ( QDataStream & in , QPair < T1 , T2 > & pair )

Reads a pair from stream in into pair .

This function requires the T1 and T2 types to implement operator>>() .

另请参阅 序列化 Qt 数据类型 .