The QStack class is a template class that provides a stack. 更多...
头: | #include <QStack> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
继承: | QList |
注意: 此类的所有函数 可重入 .
T | pop () |
void | push (const T & t ) |
void | swap (QStack<T> & other ) |
T & | top () |
const T & | top () const |
QStack<T> is one of Qt's generic 容器类 . It implements a stack data structure for items of a same type.
A stack is a last in, first out (LIFO) structure. Items are added to the top of the stack using push () and retrieved from the top using pop ()。 top () function provides access to the topmost item without removing it.
范例:
QStack<int> stack; stack.push(1); stack.push(2); stack.push(3); while (!stack.isEmpty()) cout << stack.pop() << Qt::endl;
The example will output 3, 2, 1 in that order.
QStack inherits from QList 。所有 QList 's functionality also applies to QStack. For example, you can use isEmpty () to test whether the stack is empty, and you can traverse a QStack using QList 的迭代器类 (例如: QListIterator ). But in addition, QStack provides three convenience functions that make it easy to implement LIFO semantics: push (), pop (),和 top ().
QStack's value type must be an 可赋值数据类型 . This covers most data types that are commonly used, but the compiler won't let you, for example, store a QWidget 作为值;取而代之,存储 QWidget *.
Removes the top item from the stack and returns it. This function assumes that the stack isn't empty.
另请参阅 top (), push (),和 isEmpty ().
Adds element t to the top of the stack.
这如同 QList::append ().
[noexcept]
void
QStack::
swap
(
QStack
<
T
> &
other
)
Swaps stack other with this stack. This operation is very fast and never fails.
Returns a reference to the stack's top item. This function assumes that the stack isn't empty.
这如同 QList::last ().
另请参阅 pop (), push (),和 isEmpty ().
这是重载函数。