<?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[QStackedWidget (index out of range)]]></title><description><![CDATA[<p dir="auto">I am using QStackedWidget for my app which has more than 30 screens, I am facing the error "index out of range". How can I deal with this error? I've also tried to use a multi-level stacked widget yet can't get rid of that error.</p>
<p dir="auto">Please guide,</p>
]]></description><link>https://forum.qt.io/topic/110251/qstackedwidget-index-out-of-range</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 02:48:19 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/110251.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 02 Jan 2020 03:23:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Sun, 05 Jan 2020 14:30:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> yes, error was related to QList which was a part of the widget. and when I try to add that widget to stack then it makes the app crash.</p>
]]></description><link>https://forum.qt.io/post/570527</link><guid isPermaLink="true">https://forum.qt.io/post/570527</guid><dc:creator><![CDATA[ahsan737]]></dc:creator><pubDate>Sun, 05 Jan 2020 14:30:10 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Fri, 03 Jan 2020 18:58:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ahsan737">@<bdi>ahsan737</bdi></a><br />
Good you found it.<br />
So the QList it had the error about was one of the widget that you inserted into the stacked so it seemed it was related to that ?</p>
]]></description><link>https://forum.qt.io/post/570322</link><guid isPermaLink="true">https://forum.qt.io/post/570322</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 03 Jan 2020 18:58:02 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Fri, 03 Jan 2020 02:44:06 GMT]]></title><description><![CDATA[<p dir="auto">Thanks a lot,  for your dedicated and kind response, the issue is resolved.  It was being caused because the application was failing to read the initial configuration file as I mistakenly forgot calling a class in the startup. Silly yet frustrating mistake,</p>
]]></description><link>https://forum.qt.io/post/570206</link><guid isPermaLink="true">https://forum.qt.io/post/570206</guid><dc:creator><![CDATA[ahsan737]]></dc:creator><pubDate>Fri, 03 Jan 2020 02:44:06 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 23:21:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> said in <a href="/post/570180">QStackedWidget (index out of range)</a>:</p>
<blockquote>
<p dir="auto">So I guess this calls for a back trace as Christian is after :)</p>
</blockquote>
<p dir="auto">Agreed</p>
]]></description><link>https://forum.qt.io/post/570190</link><guid isPermaLink="true">https://forum.qt.io/post/570190</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 02 Jan 2020 23:21:55 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 21:46:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
Hi<br />
I recalled having a off by one error with a stackedwidget and it seemed to just ignore it - back then so felt the urge to use the source.</p>
<p dir="auto">To Make it more interesting,  QCustomPlot seems to be using a QVector but<br />
the actual error is<br />
ASSERT failure in QList&lt;T&gt;</p>
<p dir="auto">So I guess this calls for a back trace as Christian is after :)</p>
]]></description><link>https://forum.qt.io/post/570180</link><guid isPermaLink="true">https://forum.qt.io/post/570180</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 02 Jan 2020 21:46:42 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 21:40:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> Exactly what I was double checking :-)</p>
]]></description><link>https://forum.qt.io/post/570178</link><guid isPermaLink="true">https://forum.qt.io/post/570178</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 02 Jan 2020 21:40:27 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 21:24:15 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
I'm not sure the stackedwidget in itself is to blame for the index out of range.<br />
If i do this<br />
ui-&gt;stackedWidget-&gt;setCurrentIndex(1000);<br />
in a blank GUI project. Nothing is shown and app just starts.<br />
Also in the inner code, the index is checked.</p>
<pre><code>QWidget *QStackedLayout::widget(int index) const
{
    Q_D(const QStackedLayout);
     if (index &lt; 0 || index &gt;= d-&gt;list.size())
        return nullptr;
    return d-&gt;list.at(index)-&gt;widget();
}

</code></pre>
]]></description><link>https://forum.qt.io/post/570176</link><guid isPermaLink="true">https://forum.qt.io/post/570176</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 02 Jan 2020 21:24:15 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 16:24:19 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<blockquote>
<p dir="auto">void MainWindow::_onNext()<br />
{<br />
int Index=ui-&gt;stackedWidget-&gt;currentIndex();<br />
Index++;<br />
ui-&gt;stackedWidget-&gt;setCurrentIndex(Index);<br />
}</p>
</blockquote>
<p dir="auto">You are missing the boundary check so suggested by @JonB.</p>
]]></description><link>https://forum.qt.io/post/570108</link><guid isPermaLink="true">https://forum.qt.io/post/570108</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 02 Jan 2020 16:24:19 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 16:21:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ahsan737">@<bdi>ahsan737</bdi></a> said in <a href="/post/570005">QStackedWidget (index out of range)</a>:</p>
<blockquote>
<p dir="auto">Move to next Index</p>
</blockquote>
<p dir="auto">Did you actually check what <a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> wrote?<br />
Can you post the complete backtrace?</p>
]]></description><link>https://forum.qt.io/post/570107</link><guid isPermaLink="true">https://forum.qt.io/post/570107</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Thu, 02 Jan 2020 16:21:28 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 11:46:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ahsan737">@<bdi>ahsan737</bdi></a><br />
Are you sure its not empty and you connected signals to some slot so it tried to do something ?<br />
Try adding a new QCustomPlot instead and see.</p>
<p dir="auto">ui-&gt;stackedWidget-&gt;addWidget(new QCustomPlot (this) );</p>
<p dir="auto">to see if that also gives same error.</p>
]]></description><link>https://forum.qt.io/post/570053</link><guid isPermaLink="true">https://forum.qt.io/post/570053</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 02 Jan 2020 11:46:23 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 11:43:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> this UI containing QCustomPlot and Graph works fine, but gives an error when I add it to QStackedWidget. How can it possibly be evaluated?</p>
]]></description><link>https://forum.qt.io/post/570051</link><guid isPermaLink="true">https://forum.qt.io/post/570051</guid><dc:creator><![CDATA[ahsan737]]></dc:creator><pubDate>Thu, 02 Jan 2020 11:43:31 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 10:36:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ahsan737">@<bdi>ahsan737</bdi></a><br />
Hi<br />
Promoting a widget is merely an editor stunt, where it replaces the generic type with<br />
a user type in the code generator.<br />
As soon as code runs, it is no different from simply newing your own type.</p>
<p dir="auto">However, customplot might use a QList internally and maybe that's the one that<br />
gives this error.</p>
]]></description><link>https://forum.qt.io/post/570034</link><guid isPermaLink="true">https://forum.qt.io/post/570034</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 02 Jan 2020 10:36:30 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 10:15:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> I have noticed that a particular widget is causing the problem. Whenever I try to add that widget then the error appears. In that widget, I am plotting a line graph using QCustomPlot. Is that promoted widget causing the problem?</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/f8eaac9d-ce69-408e-986b-4756100a3b16.JPG" alt="捕获.JPG" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/570029</link><guid isPermaLink="true">https://forum.qt.io/post/570029</guid><dc:creator><![CDATA[ahsan737]]></dc:creator><pubDate>Thu, 02 Jan 2020 10:15:50 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 09:27:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ahsan737">@<bdi>ahsan737</bdi></a><br />
So print out the value of <code>Index</code> if you want to know why it is out of range!  From your code if <code>ui-&gt;stackedWidget-&gt;currentIndex()</code> is presently on the last widget in the stack it's going to go out of range.</p>
]]></description><link>https://forum.qt.io/post/570013</link><guid isPermaLink="true">https://forum.qt.io/post/570013</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 02 Jan 2020 09:27:09 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 09:14:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a>   but if I add fewer widgets then everything works fine.</p>
]]></description><link>https://forum.qt.io/post/570011</link><guid isPermaLink="true">https://forum.qt.io/post/570011</guid><dc:creator><![CDATA[ahsan737]]></dc:creator><pubDate>Thu, 02 Jan 2020 09:14:21 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 09:08:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> I have just loaded these widgets, and when I deploy on the device then the app crash at the start even before I do anything.</p>
<blockquote>
<p dir="auto"><em><strong>Error</strong></em></p>
</blockquote>
<pre><code>F libFBC3.so: ASSERT failure in QList&lt;T&gt;::at: "index out of range",
</code></pre>
<blockquote>
<p dir="auto"><strong>Move to next Index</strong></p>
</blockquote>
<pre><code>void MainWindow::_onNext()
{
    int Index=ui-&gt;stackedWidget-&gt;currentIndex();
    Index++;
    ui-&gt;stackedWidget-&gt;setCurrentIndex(Index);
}
</code></pre>
<blockquote>
<p dir="auto"><strong>Added Widgets</strong></p>
</blockquote>
<pre><code>                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_screen);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_newMeasure);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_manual1);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_manual2);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_1_1);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_1_2);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_1_3);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_3);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_4);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_5);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_6);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_7);   
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_10);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_8);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_9);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_prep_2);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_static_1);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_staticInstruct_1);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_staticInstruct_2);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_staticInstruct_3);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_staticInstruct_4);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_staticInstruct_5);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_staticInstruct_6);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_staticInstruct_7);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_staticInstruct_8);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_staticMeasure);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_dynamicInstruct_1);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_dynamicInstruct_2);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_dynamicInstruct_3);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_dynamicMeasure);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_dynamicPrep);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_saveData);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_secondPrep_1);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_secondPrep_2);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_secondPrep_3);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_secondPrep_4);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_secondPrep_5);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_secondPrep_6);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_settings);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_admin);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_showdata);
                        ui-&gt;stackedWidget-&gt;addWidget(&amp;_btSettings);
</code></pre>
]]></description><link>https://forum.qt.io/post/570005</link><guid isPermaLink="true">https://forum.qt.io/post/570005</guid><dc:creator><![CDATA[ahsan737]]></dc:creator><pubDate>Thu, 02 Jan 2020 09:08:30 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 08:04:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ahsan737">@<bdi>ahsan737</bdi></a><br />
Make it so the index you are passing is <code>0 &lt;= index &lt; QStackedWidget.count()</code>.  Violating that is the only reason for that message.  There isn't a limit on the number of widget pages you can have in a stacked widget.</p>
]]></description><link>https://forum.qt.io/post/569995</link><guid isPermaLink="true">https://forum.qt.io/post/569995</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 02 Jan 2020 08:04:35 GMT</pubDate></item><item><title><![CDATA[Reply to QStackedWidget (index out of range) on Thu, 02 Jan 2020 07:00:45 GMT]]></title><description><![CDATA[<p dir="auto">When does that error show up? Are you 100% sure you are not trying to open a widget at invalid index?</p>
]]></description><link>https://forum.qt.io/post/569982</link><guid isPermaLink="true">https://forum.qt.io/post/569982</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Thu, 02 Jan 2020 07:00:45 GMT</pubDate></item></channel></rss>