6.0.0-rc4Source

QStack Class

template <typename T> class QStack

The QStack class is a template class that provides a stack. More…

Header#include <QStack>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
InheritsQList

List of all members, including inherited members

Public Functions

voidpush(const T &t)
Tpop()
T &top()
const T &top() const

Detailed Description

QStack<T> is a QList<T> with last-in, first-out operations: items are added with push() and taken from the top with pop(). All of QList's functions are available.

QStack<int> stack;
stack.push(1);
stack.push(2);
int top = stack.pop(); // 2

See also QList and QQueue.

Differences from Qt

The class is a plain subclass of QList that adds only push(), pop() and top(). It has no further members.

Member Function Documentation

T QStack::pop()

Removes the top item from the stack and returns it. The stack must not be empty.

See also push() and top().

void QStack::push(const T &t)

Adds t to the top of the stack.

See also pop() and top().

T & QStack::top()

Returns a reference to the item at the top of the stack. The stack must not be empty.

See also push() and pop().

const T & QStack::top() const

This is an overloaded function.

Returns a const reference to the item at the top of the stack.