Obsolete Members for <QtAlgorithms>

以下成员源于类 <QtAlgorithms> 已过时。 提供它们是为使旧源代码能继续工作。强烈建议不要在新代码中使用它们。

函数

(obsolete) RandomAccessIterator qBinaryFind (RandomAccessIterator begin , RandomAccessIterator end , const T & value )
(obsolete) RandomAccessIterator qBinaryFind (RandomAccessIterator begin , RandomAccessIterator end , const T & value , LessThan lessThan )
(obsolete) typename Container::const_iterator qBinaryFind (const Container & container , const T & value )
(obsolete) OutputIterator qCopy (InputIterator begin1 , InputIterator end1 , OutputIterator begin2 )
(obsolete) BiIterator2 qCopyBackward (BiIterator1 begin1 , BiIterator1 end1 , BiIterator2 end2 )
(obsolete) void qCount (InputIterator begin , InputIterator end , const T & value , Size & n )
(obsolete) void qCount (const Container & container , const T & value , Size & n )
(obsolete) bool qEqual (InputIterator1 begin1 , InputIterator1 end1 , InputIterator2 begin2 )
(obsolete) void qFill (ForwardIterator begin , ForwardIterator end , const T & value )
(obsolete) void qFill (Container & container , const T & value )
(obsolete) InputIterator qFind (InputIterator begin , InputIterator end , const T & value )
(obsolete) typename Container::const_iterator qFind (const Container & container , const T & value )
(obsolete) LessThan qGreater ()
(obsolete) LessThan qLess ()
(obsolete) RandomAccessIterator qLowerBound (RandomAccessIterator begin , RandomAccessIterator end , const T & value )
(obsolete) RandomAccessIterator qLowerBound (RandomAccessIterator begin , RandomAccessIterator end , const T & value , LessThan lessThan )
(obsolete) typename Container::const_iterator qLowerBound (const Container & container , const T & value )
(obsolete) void qSort (RandomAccessIterator begin , RandomAccessIterator end )
(obsolete) void qSort (RandomAccessIterator begin , RandomAccessIterator end , LessThan lessThan )
(obsolete) void qSort (Container & container )
(obsolete) void qStableSort (RandomAccessIterator begin , RandomAccessIterator end )
(obsolete) void qStableSort (RandomAccessIterator begin , RandomAccessIterator end , LessThan lessThan )
(obsolete) void qStableSort (Container & container )
(obsolete) RandomAccessIterator qUpperBound (RandomAccessIterator begin , RandomAccessIterator end , const T & value )
(obsolete) RandomAccessIterator qUpperBound (RandomAccessIterator begin , RandomAccessIterator end , const T & value , LessThan lessThan )
(obsolete) typename Container::const_iterator qUpperBound (const Container & container , const T & value )

函数文档编制

template <typename RandomAccessIterator, typename T> RandomAccessIterator qBinaryFind ( RandomAccessIterator begin , RandomAccessIterator end , const T & value )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::binary_search or std::lower_bound 代替。

Performs a binary search of the range [ begin , end ) and returns the position of an occurrence of value . If there are no occurrences of value ,返回 end .

The items in the range [ begin , end ) must be sorted in ascending order; see qSort ().

If there are many occurrences of the same value, any one of them could be returned. Use qLowerBound () 或 qUpperBound () if you need finer control.

范例:

QVector<int> vect;
vect << 3 << 3 << 6 << 6 << 6 << 8;
QVector<int>::iterator i =
        qBinaryFind(vect.begin(), vect.end(), 6);
// i == vect.begin() + 2 (or 3 or 4)
					

This function requires the item type (in the example above, QString ) to implement operator<() .

另请参阅 qLowerBound (), qUpperBound (),和 random access iterators .

template <typename RandomAccessIterator, typename T, typename LessThan> RandomAccessIterator qBinaryFind ( RandomAccessIterator begin , RandomAccessIterator end , const T & value , LessThan lessThan )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::binary_search or std::lower_bound 代替。

使用 lessThan function instead of operator<() to compare the items.

Note that the items in the range must be sorted according to the order specified by the lessThan 对象。

template <typename Container, typename T> typename Container::const_iterator qBinaryFind (const Container & container , const T & value )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::binary_search or std::lower_bound 代替。

This is the same as qBinaryFind( container .begin(), container .end(), value );

template <typename InputIterator, typename OutputIterator> OutputIterator qCopy ( InputIterator begin1 , InputIterator end1 , OutputIterator begin2 )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::copy 代替。

Copies the items from range [ begin1 , end1 ) to range [ begin2 , ...), in the order in which they appear.

The item at position begin1 is assigned to that at position begin2 ; the item at position begin1 + 1 is assigned to that at position begin2 + 1; and so on.

范例:

QStringList list;
list << "one" << "two" << "three";
QVector<QString> vect1(3);
qCopy(list.begin(), list.end(), vect1.begin());
// vect: [ "one", "two", "three" ]
QVector<QString> vect2(8);
qCopy(list.begin(), list.end(), vect2.begin() + 2);
// vect: [ "", "", "one", "two", "three", "", "", "" ]
					

另请参阅 qCopyBackward (), input iterators ,和 output iterators .

template <typename BiIterator1, typename BiIterator2> BiIterator2 qCopyBackward ( BiIterator1 begin1 , BiIterator1 end1 , BiIterator2 end2 )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::copy_backward 代替。

Copies the items from range [ begin1 , end1 ) to range [..., end2 ).

The item at position end1 - 1 is assigned to that at position end2 - 1; the item at position end1 - 2 is assigned to that at position end2 - 2; and so on.

范例:

QStringList list;
list << "one" << "two" << "three";
QVector<QString> vect(5);
qCopyBackward(list.begin(), list.end(), vect.end());
// vect: [ "", "", "one", "two", "three" ]
					

另请参阅 qCopy () 和 bidirectional iterators .

template <typename InputIterator, typename T, typename Size> void qCount ( InputIterator begin , InputIterator end , const T & value , Size & n )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::count 代替。

Returns the number of occurrences of value in the range [ begin , end ), which is returned in n . n is never initialized, the count is added to n . It is the caller's responsibility to initialize n .

范例:

QList<int> list;
list << 3 << 3 << 6 << 6 << 6 << 8;
int countOf6 = 0;
qCount(list.begin(), list.end(), 6, countOf6);
// countOf6 == 3
int countOf7 = 0;
qCount(list.begin(), list.end(), 7, countOf7);
// countOf7 == 0
					

This function requires the item type (in the example above, int ) to implement operator==() .

另请参阅 input iterators .

template <typename Container, typename T, typename Size> void qCount (const Container & container , const T & value , Size & n )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::count 代替。

Instead of operating on iterators, as in the other overload, this function operates on the specified container to obtain the number of instances of value in the variable passed as a reference in argument n .

template <typename InputIterator1, typename InputIterator2> bool qEqual ( InputIterator1 begin1 , InputIterator1 end1 , InputIterator2 begin2 )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::equal 代替。

Compares the items in the range [ begin1 , end1 ) with the items in the range [ begin2 , ...). Returns true if all the items compare equal; otherwise returns false .

范例:

QStringList list;
list << "one" << "two" << "three";
QVector<QString> vect(3);
vect[0] = "one";
vect[1] = "two";
vect[2] = "three";
bool ret1 = qEqual(list.begin(), list.end(), vect.begin());
// ret1 == true
vect[2] = "seven";
bool ret2 = qEqual(list.begin(), list.end(), vect.begin());
// ret2 == false
					

This function requires the item type (in the example above, QString ) to implement operator==() .

另请参阅 input iterators .

template <typename ForwardIterator, typename T> void qFill ( ForwardIterator begin , ForwardIterator end , const T & value )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::fill 代替。

Fills the range [ begin , end ) with value .

范例:

QStringList list;
list << "one" << "two" << "three";
qFill(list.begin(), list.end(), "eleven");
// list: [ "eleven", "eleven", "eleven" ]
qFill(list.begin() + 1, list.end(), "six");
// list: [ "eleven", "six", "six" ]
					

另请参阅 qCopy () 和 forward iterators .

template <typename Container, typename T> void qFill ( Container & container , const T & value )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::fill 代替。

This is the same as qFill( container .begin(), container .end(), value );

template <typename InputIterator, typename T> InputIterator qFind ( InputIterator begin , InputIterator end , const T & value )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::find 代替。

Returns an iterator to the first occurrence of value in a container in the range [ begin , end ). Returns end if value isn't found.

范例:

QStringList list;
list << "one" << "two" << "three";
QStringList::iterator i1 = qFind(list.begin(), list.end(), "two");
// i1 == list.begin() + 1
QStringList::iterator i2 = qFind(list.begin(), list.end(), "seventy");
// i2 == list.end()
					

This function requires the item type (in the example above, QString ) to implement operator==() .

If the items in the range are in ascending order, you can get faster results by using qLowerBound () 或 qBinaryFind () instead of qFind().

另请参阅 qBinaryFind () 和 input iterators .

template <typename Container, typename T> typename Container::const_iterator qFind (const Container & container , const T & value )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::find 代替。

This is the same as qFind( container .constBegin(), container .constEnd(), value );

template <typename T> LessThan qGreater ()

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::greater 代替。

Returns a functional object, or functor, that can be passed to qSort () 或 qStableSort ().

范例:

QList<int> list;
list << 33 << 12 << 68 << 6 << 12;
qSort(list.begin(), list.end(), qGreater<int>());
// list: [ 68, 33, 12, 12, 6 ]
					

另请参阅 qLess<T> ().

template <typename T> LessThan qLess ()

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::less 代替。

Returns a functional object, or functor, that can be passed to qSort () 或 qStableSort ().

范例:

QList<int> list;
list << 33 << 12 << 68 << 6 << 12;
qSort(list.begin(), list.end(), qLess<int>());
// list: [ 6, 12, 12, 33, 68 ]
					

另请参阅 qGreater<T> ().

template <typename RandomAccessIterator, typename T> RandomAccessIterator qLowerBound ( RandomAccessIterator begin , RandomAccessIterator end , const T & value )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::lower_bound 代替。

Performs a binary search of the range [ begin , end ) and returns the position of the first occurrence of value . If no such item is found, returns the position where it should be inserted.

The items in the range [ begin , end ) must be sorted in ascending order; see qSort ().

范例:

QList<int> list;
list << 3 << 3 << 6 << 6 << 6 << 8;
QList<int>::iterator i = qLowerBound(list.begin(), list.end(), 5);
list.insert(i, 5);
// list: [ 3, 3, 5, 6, 6, 6, 8 ]
i = qLowerBound(list.begin(), list.end(), 12);
list.insert(i, 12);
// list: [ 3, 3, 5, 6, 6, 6, 8, 12 ]
					

This function requires the item type (in the example above, int ) to implement operator<() .

qLowerBound() can be used in conjunction with qUpperBound () to iterate over all occurrences of the same value:

QVector<int> vect;
vect << 3 << 3 << 6 << 6 << 6 << 8;
QVector<int>::iterator begin6 =
        qLowerBound(vect.begin(), vect.end(), 6);
QVector<int>::iterator end6 =
        qUpperBound(begin6, vect.end(), 6);
QVector<int>::iterator i = begin6;
while (i != end6) {
    *i = 7;
    ++i;
}
// vect: [ 3, 3, 7, 7, 7, 8 ]
					

另请参阅 qUpperBound () 和 qBinaryFind ().

template <typename RandomAccessIterator, typename T, typename LessThan> RandomAccessIterator qLowerBound ( RandomAccessIterator begin , RandomAccessIterator end , const T & value , LessThan lessThan )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::lower_bound 代替。

使用 lessThan function instead of operator<() to compare the items.

Note that the items in the range must be sorted according to the order specified by the lessThan 对象。

template <typename Container, typename T> typename Container::const_iterator qLowerBound (const Container & container , const T & value )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::lower_bound 代替。

For read-only iteration over containers, this function is broadly equivalent to qLowerBound( container .begin(), container .end(), value). However, since it returns a const iterator, you cannot use it to modify the container; for example, to insert items.

template <typename RandomAccessIterator> void qSort ( RandomAccessIterator begin , RandomAccessIterator end )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::sort 代替。

Sorts the items in range [ begin , end ) in ascending order using the quicksort algorithm.

范例:

QList<int> list;
list << 33 << 12 << 68 << 6 << 12;
qSort(list.begin(), list.end());
// list: [ 6, 12, 12, 33, 68 ]
					

The sort algorithm is efficient on large data sets. It operates in linear-logarithmic time , O( n log n ).

This function requires the item type (in the example above, int ) to implement operator<() .

If neither of the two items is "less than" the other, the items are taken to be equal. It is then undefined which one of the two items will appear before the other after the sort.

另请参阅 qStableSort () 和 random access iterators .

template <typename RandomAccessIterator, typename LessThan> void qSort ( RandomAccessIterator begin , RandomAccessIterator end , LessThan lessThan )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::sort 代替。

使用 lessThan function instead of operator<() to compare the items.

For example, here's how to sort the strings in a QStringList in case-insensitive alphabetical order:

bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
{
    return s1.toLower() < s2.toLower();
}
int doSomething()
{
    QStringList list;
    list << "AlPha" << "beTA" << "gamma" << "DELTA";
    qSort(list.begin(), list.end(), caseInsensitiveLessThan);
    // list: [ "AlPha", "beTA", "DELTA", "gamma" ]
}
					

To sort values in reverse order, pass qGreater<T> () as the lessThan 参数。例如:

QList<int> list;
list << 33 << 12 << 68 << 6 << 12;
qSort(list.begin(), list.end(), qGreater<int>());
// list: [ 68, 33, 12, 12, 6 ]
					

If neither of the two items is "less than" the other, the items are taken to be equal. It is then undefined which one of the two items will appear before the other after the sort.

An alternative to using qSort() is to put the items to sort in a QMap , using the sort key as the QMap key. This is often more convenient than defining a lessThan function. For example, the following code shows how to sort a list of strings case insensitively using QMap :

QStringList list;
list << "AlPha" << "beTA" << "gamma" << "DELTA";
QMap<QString, QString> map;
foreach (const QString &str, list)
    map.insert(str.toLower(), str);
list = map.values();
					

另请参阅 QMap .

template <typename Container> void qSort ( Container & container )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::sort 代替。

This is the same as qSort( container .begin(), container .end());

template <typename RandomAccessIterator> void qStableSort ( RandomAccessIterator begin , RandomAccessIterator end )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::stable_sort 代替。

Sorts the items in range [ begin , end ) in ascending order using a stable sorting algorithm.

If neither of the two items is "less than" the other, the items are taken to be equal. The item that appeared before the other in the original container will still appear first after the sort. This property is often useful when sorting user-visible data.

范例:

QList<int> list;
list << 33 << 12 << 68 << 6 << 12;
qStableSort(list.begin(), list.end());
// list: [ 6, 12, 12, 33, 68 ]
					

The sort algorithm is efficient on large data sets. It operates in linear-logarithmic time , O( n log n ).

This function requires the item type (in the example above, int ) to implement operator<() .

另请参阅 qSort () 和 random access iterators .

template <typename RandomAccessIterator, typename LessThan> void qStableSort ( RandomAccessIterator begin , RandomAccessIterator end , LessThan lessThan )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::stable_sort 代替。

使用 lessThan function instead of operator<() to compare the items.

For example, here's how to sort the strings in a QStringList in case-insensitive alphabetical order:

bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
{
    return s1.toLower() < s2.toLower();
}
int doSomething()
{
    QStringList list;
    list << "AlPha" << "beTA" << "gamma" << "DELTA";
    qStableSort(list.begin(), list.end(), caseInsensitiveLessThan);
    // list: [ "AlPha", "beTA", "DELTA", "gamma" ]
}
					

Note that earlier versions of Qt allowed using a lessThan function that took its arguments by non-const reference. From 4.3 and on this is no longer possible, the arguments has to be passed by const reference or value.

To sort values in reverse order, pass qGreater<T> () as the lessThan 参数。例如:

QList<int> list;
list << 33 << 12 << 68 << 6 << 12;
qStableSort(list.begin(), list.end(), qGreater<int>());
// list: [ 68, 33, 12, 12, 6 ]
					

If neither of the two items is "less than" the other, the items are taken to be equal. The item that appeared before the other in the original container will still appear first after the sort. This property is often useful when sorting user-visible data.

template <typename Container> void qStableSort ( Container & container )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::stable_sort 代替。

This is the same as qStableSort( container .begin(), container .end());

template <typename RandomAccessIterator, typename T> RandomAccessIterator qUpperBound ( RandomAccessIterator begin , RandomAccessIterator end , const T & value )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

使用 std::upper_bound 代替。

Performs a binary search of the range [ begin , end ) and returns the position of the one-past-the-last occurrence of value . If no such item is found, returns the position where the item should be inserted.

The items in the range [ begin , end ) must be sorted in ascending order; see qSort ().

范例:

QList<int> list;
list << 3 << 3 << 6 << 6 << 6 << 8;
QList<int>::iterator i = qUpperBound(list.begin(), list.end(), 5);
list.insert(i, 5);
// list: [ 3, 3, 5, 6, 6, 6, 8 ]
i = qUpperBound(list.begin(), list.end(), 12);
list.insert(i, 12);
// list: [ 3, 3, 5, 6, 6, 6, 8, 12 ]
					

This function requires the item type (in the example above, int ) to implement operator<() .

qUpperBound() can be used in conjunction with qLowerBound () to iterate over all occurrences of the same value:

QVector<int> vect;
vect << 3 << 3 << 6 << 6 << 6 << 8;
QVector<int>::iterator begin6 =
        qLowerBound(vect.begin(), vect.end(), 6);
QVector<int>::iterator end6 =
        qUpperBound(vect.begin(), vect.end(), 6);
QVector<int>::iterator i = begin6;
while (i != end6) {
    *i = 7;
    ++i;
}
// vect: [ 3, 3, 7, 7, 7, 8 ]
					

另请参阅 qLowerBound () 和 qBinaryFind ().

template <typename RandomAccessIterator, typename T, typename LessThan> RandomAccessIterator qUpperBound ( RandomAccessIterator begin , RandomAccessIterator end , const T & value , LessThan lessThan )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::upper_bound 代替。

使用 lessThan function instead of operator<() to compare the items.

Note that the items in the range must be sorted according to the order specified by the lessThan 对象。

template <typename Container, typename T> typename Container::const_iterator qUpperBound (const Container & container , const T & value )

此函数已过时。提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

这是重载函数。

使用 std::upper_bound 代替。

This is the same as qUpperBound( container .begin(), container .end(), value );