QStackmyStack; if (myStack.isEmpty()) { qDebug() << "Stack is empty"; } else { qDebug() << "Stack is not empty"; }
QStackIn this example, a new stack called myStack is created and a few elements are added to it. Then, a while loop is used to remove each element one by one using the pop function until the stack is empty. A debug message showing the item popped out is printed for each iteration. Package/library Name: QtmyStack; myStack.push("Apple"); myStack.push("Banana"); myStack.push("Cherry"); while (!myStack.isEmpty()) { qDebug() << "Popped item:" << myStack.pop(); }