QStack Class
template <typename T> class QStack
The QStack class is a template class that provides a stack. More…
| Header | #include <QStack> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
| Inherits | QList |
List of all members, including inherited members
Public Functions
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
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.
void QStack::push(const T &t)
Adds t to the top of the stack.
T & QStack::top()
Returns a reference to the item at the top of the stack. The stack must not be empty.
const T & QStack::top() const
This is an overloaded function.
Returns a const reference to the item at the top of the stack.