QStack<QJsonValue>, peek not found...
-
I am using a QStack<QJsonValue>, in my push function I want to check if the last value push is the same and if yes, do nothing, my pseudo logic:
1. Does stack contain at least 1 item? 2. If No goto 5 3. If Yes, is the last entry pushed the same as the new value waiting to be pushed? 4. Yes, its the same, do nothing and return 5. Push new value to stack.
From searching google it seems that a peek use to be available, I'm using Qt 5.15.2
-
@SPlatten said in QStack<QJsonValue>, peek not found...:
const QJsonValue& crobjLast(last());
You should use QStack::top()
-
@SPlatten said in QStack<QJsonValue>, peek not found...:
From searching google it seems that a peek use to be available, I'm using Qt 5.15.2
Why not simply looking in the documentation?
-
@Christian-Ehrlicher , just implemented:
void clsQtJsonStack::push(const QJsonValue& crobjValue) { if ( isEmpty() != true ) { //Get last value pushed to stack const QJsonValue& crobjLast(last()); if ( crobjLast == crobjValue ) { //Last is same as new value, do nothing return; } } QStack::push(crobjValue); }
-
@SPlatten said in QStack<QJsonValue>, peek not found...:
const QJsonValue& crobjLast(last());
You should use QStack::top()
-
@Christian-Ehrlicher, thank you, just realised the same during debugging.