<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Using QStack, how to remove at specific location.]]></title><description><![CDATA[<p dir="auto">I am using a QStack to create an undo / redo stack:</p>
<pre><code>    class clsQtJsonStack : public QStack&lt;QJsonObject&gt; {
    private:

    public:
        clsQtJsonStack();
        int intPush(const QJsonObject&amp; crJSON);
    };
</code></pre>
<p dir="auto">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 <strong>at</strong>.  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.</p>
<p dir="auto">Looking at how to use <strong>remove</strong> and <strong>removeAt</strong>, the documentation isn't create because both these expect a <strong>qsizetype</strong> parameter, is this just an integer cast as <strong>qsizetype</strong> ?</p>
]]></description><link>https://forum.qt.io/topic/142710/using-qstack-how-to-remove-at-specific-location</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 16:28:11 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/142710.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 05 Feb 2023 15:40:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Using QStack, how to remove at specific location. on Sun, 05 Feb 2023 17:12:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a>: I agree with <a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> - it looks scary to remove items from the middle of a stack.<br />
As you have correctly noticed, <code>QStack</code>is a thin wrapper around <code>QList</code>, which provides access to all its container functions.<br />
In your research about those, you were just one double click away from the answer to your actual question: <code>qsizetype</code>is a signed version of <code>size_t</code>.<br />
<code>using qsizetype = QIntegerForSizeof&lt;std::size_t&gt;::Signed;</code></p>
]]></description><link>https://forum.qt.io/post/746372</link><guid isPermaLink="true">https://forum.qt.io/post/746372</guid><dc:creator><![CDATA[Axel Spoerl]]></dc:creator><pubDate>Sun, 05 Feb 2023 17:12:30 GMT</pubDate></item><item><title><![CDATA[Reply to Using QStack, how to remove at specific location. on Sun, 05 Feb 2023 17:34:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a><br />
Then you can use the methods derived from <code>QList</code>.  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 use <code>push()</code> and <code>pop()</code>.</p>
<blockquote>
<p dir="auto">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.</p>
</blockquote>
<p dir="auto">This is just <a href="https://doc.qt.io/qt-6/qstack.html#pop" target="_blank" rel="noopener noreferrer nofollow ugc">T QStack::pop()</a>, and you don't need any *remove at specific index".</p>
<p dir="auto">Yes the methods which take a <code>qsizetype</code> as an index accept an integer.</p>
]]></description><link>https://forum.qt.io/post/746371</link><guid isPermaLink="true">https://forum.qt.io/post/746371</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 05 Feb 2023 17:34:10 GMT</pubDate></item><item><title><![CDATA[Reply to Using QStack, how to remove at specific location. on Sun, 05 Feb 2023 16:57:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> , according to the documentation:<br />
<a href="https://doc.qt.io/qt-6/qstack.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qstack.html</a></p>
<p dir="auto">The class is derived from <strong>QList</strong>, <strong>QList</strong> does have <strong>remove</strong>:<br />
<a href="https://doc.qt.io/qt-6/qlist.html#remove" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qlist.html#remove</a></p>
<p dir="auto">And <strong>removeAt</strong>:<br />
<a href="https://doc.qt.io/qt-6/qlist.html#removeAt" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qlist.html#removeAt</a></p>
]]></description><link>https://forum.qt.io/post/746370</link><guid isPermaLink="true">https://forum.qt.io/post/746370</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Sun, 05 Feb 2023 16:57:56 GMT</pubDate></item><item><title><![CDATA[Reply to Using QStack, how to remove at specific location. on Sun, 05 Feb 2023 16:01:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a> said in <a href="/post/746360">Using QStack, how to remove at specific location.</a>:</p>
<blockquote>
<p dir="auto">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.</p>
</blockquote>
<p dir="auto">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.</p>
]]></description><link>https://forum.qt.io/post/746364</link><guid isPermaLink="true">https://forum.qt.io/post/746364</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sun, 05 Feb 2023 16:01:27 GMT</pubDate></item></channel></rss>