Using QStack, how to remove at specific location.
-
I am using a QStack to create an undo / redo stack:
class clsQtJsonStack : public QStack<QJsonObject> { private: public: clsQtJsonStack(); int intPush(const QJsonObject& crJSON); };As I edit a control the data is pushed onto the stack. When I undo I take the data from the last undo position, using at. This doesn't remove the item from the stack, how should I do this because looking at the documentation there doesn't appear to be a call to remove an item at a specific index.
Looking at how to use remove and removeAt, the documentation isn't create because both these expect a qsizetype parameter, is this just an integer cast as qsizetype ?
-
I am using a QStack to create an undo / redo stack:
class clsQtJsonStack : public QStack<QJsonObject> { private: public: clsQtJsonStack(); int intPush(const QJsonObject& crJSON); };As I edit a control the data is pushed onto the stack. When I undo I take the data from the last undo position, using at. This doesn't remove the item from the stack, how should I do this because looking at the documentation there doesn't appear to be a call to remove an item at a specific index.
Looking at how to use remove and removeAt, the documentation isn't create because both these expect a qsizetype parameter, is this just an integer cast as qsizetype ?
@SPlatten said in Using QStack, how to remove at specific location.:
This doesn't remove the item from the stack, how should I do this because looking at the documentation there doesn't appear to be a call to remove an item at a specific index.
If it would have those function than it wouldn't be a stack. If you want to remove at a specific index use the proper container.
-
@SPlatten said in Using QStack, how to remove at specific location.:
This doesn't remove the item from the stack, how should I do this because looking at the documentation there doesn't appear to be a call to remove an item at a specific index.
If it would have those function than it wouldn't be a stack. If you want to remove at a specific index use the proper container.
@Christian-Ehrlicher , according to the documentation:
https://doc.qt.io/qt-6/qstack.htmlThe class is derived from QList, QList does have remove:
https://doc.qt.io/qt-6/qlist.html#removeAnd removeAt:
https://doc.qt.io/qt-6/qlist.html#removeAt -
@Christian-Ehrlicher , according to the documentation:
https://doc.qt.io/qt-6/qstack.htmlThe class is derived from QList, QList does have remove:
https://doc.qt.io/qt-6/qlist.html#removeAnd removeAt:
https://doc.qt.io/qt-6/qlist.html#removeAt@SPlatten
Then you can use the methods derived fromQList. In fact, if you are removing at arbitrary position it is a list rather than a stack anyway, so use that. For a stack you should just usepush()andpop().As I edit a control the data is pushed onto the stack. When I undo I take the data from the last undo position, using at. This doesn't remove the item from the stack, how should I do this because looking at the documentation there doesn't appear to be a call to remove an item at a specific index.
This is just T QStack::pop(), and you don't need any *remove at specific index".
Yes the methods which take a
qsizetypeas an index accept an integer. -
@SPlatten: I agree with @Christian-Ehrlicher - it looks scary to remove items from the middle of a stack.
As you have correctly noticed,QStackis a thin wrapper aroundQList, which provides access to all its container functions.
In your research about those, you were just one double click away from the answer to your actual question:qsizetypeis a signed version ofsize_t.
using qsizetype = QIntegerForSizeof<std::size_t>::Signed;