<?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[Filling StackedWidgets]]></title><description><![CDATA[<p dir="auto">Hello everyone I am having some troubles filling in my StackWidgets.</p>
<p dir="auto">I have created a dialog. When this is opened a list is shown to the left with some objects in it. I am trying to have some ui files I created show up to the right of the list whenever the corresponding item is selected in the list.</p>
<p dir="auto">In my dialog.cpp I included the .h file of the first ui file. After the ui is set up, I instantiate the first item and then call the stackedWidgets so that the new created instantiation is added. This is my code:</p>
<p dir="auto">#include "dialog.h"</p>
<p dir="auto">dialog::dialog(QWidget *parent)<br />
: QDialog(parent)<br />
{<br />
ui.setupUi(this);</p>
<pre><code>Item1* newItem = new Item1();
ui.stackedWidget-&gt;addWidget(newItem);
</code></pre>
<p dir="auto">}</p>
<p dir="auto">dialog::~dialog()<br />
{<br />
}</p>
<p dir="auto">When I compile and open the dialog I have my list on the left and on the right an empty space. If I click on the first item of the list my newItem instantiation is not there. What did I do wrong?</p>
<p dir="auto">Please help me understand my mistake. Thanks in advance.</p>
]]></description><link>https://forum.qt.io/topic/127236/filling-stackedwidgets</link><generator>RSS for Node</generator><lastBuildDate>Sun, 28 Jun 2026 09:46:46 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/127236.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 02 Jun 2021 12:16:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Filling StackedWidgets on Thu, 03 Jun 2021 15:07:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> I fixed it! I had some useless lines of instantiations in items 2,3 .cpp. THANK YOU!</p>
]]></description><link>https://forum.qt.io/post/663249</link><guid isPermaLink="true">https://forum.qt.io/post/663249</guid><dc:creator><![CDATA[TommyTLC]]></dc:creator><pubDate>Thu, 03 Jun 2021 15:07:51 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Thu, 03 Jun 2021 14:46:03 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
That seems odd.</p>
<p dir="auto">I assume it does print the qDebug() &lt;&lt; "hello1"; and hello2 ?</p>
<p dir="auto">Is there anything special with item2Configuration and item3Configuration.</p>
<p dir="auto">I mean like doing something in their constructor?</p>
]]></description><link>https://forum.qt.io/post/663245</link><guid isPermaLink="true">https://forum.qt.io/post/663245</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 03 Jun 2021 14:46:03 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Thu, 03 Jun 2021 14:40:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> Hello!</p>
<p dir="auto">By commenting/compiling I have managed to understand who is causing the problem.<br />
This is what the SLOT function looks like now:</p>
<p dir="auto">void ConfigurationDialog::onListItemClicked(QListWidgetItem* item)<br />
{<br />
ui.stackedWidget-&gt;setCurrentIndex(ui.listWidget-&gt;currentRow());</p>
<pre><code>if (ui.stackedWidget-&gt;currentIndex() == 0)
{
	item1Configuration* item1Widget = new item1Configuration;
	ui.stackedWidget-&gt;addWidget(item1Widget);
	ui.stackedWidget-&gt;setCurrentWidget(item1Widget);
}
else if (ui.stackedWidget-&gt;currentIndex() == 1)
{
	/*item2Configuration* item2Widget = new item2Configuration;
	ui.stackedWidget-&gt;addWidget(item2Widget);
	ui.stackedWidget-&gt;setCurrentWidget(item2Widget);*/
	qDebug() &lt;&lt; "hello1";
}
else if (ui.stackedWidget-&gt;currentIndex() == 2)
{
	/*item3Configuration* item3Widget = new item3Configuration;
	ui.stackedWidget-&gt;addWidget(item3Widget);
	ui.stackedWidget-&gt;setCurrentWidget(item3Widget);*/
	qDebug() &lt;&lt; "hello2";
}
else if (ui.stackedWidget-&gt;currentIndex() == 3)
{
	item4Configuration* item4Widget = new item4Configuration;
	ui.stackedWidget-&gt;addWidget(item4Widget);
	ui.stackedWidget-&gt;setCurrentWidget(item4Widget);
}
else if (ui.stackedWidget-&gt;currentIndex() == 4)
{
	item5Configuration* item5Widget = new item5Configuration;
	ui.stackedWidget-&gt;addWidget(item5Widget);
	ui.stackedWidget-&gt;setCurrentWidget(item5Widget);
}
</code></pre>
<p dir="auto">}</p>
<p dir="auto">This works well: the correct widget is shown when the corresponding item is selected in the qListWidget. The problem comes from Item2 and Item3 for some reason (that's why I commented them out). I do not understand what the problem could be. They are both QWidget classes created just like items 1,4,5. If included in the code they make the application freeze and then crash. Any thoughts?</p>
]]></description><link>https://forum.qt.io/post/663243</link><guid isPermaLink="true">https://forum.qt.io/post/663243</guid><dc:creator><![CDATA[TommyTLC]]></dc:creator><pubDate>Thu, 03 Jun 2021 14:40:26 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Thu, 03 Jun 2021 14:24:43 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
Looks good and was what was expected with signals / slot.</p>
<p dir="auto">try use the debugger to see where it crashes.</p>
<p dir="auto">Do you make a ConfigurationDialog in main.cpp and use instead of a MainWindow ?</p>
<p dir="auto">Did you change anything else  as I dont see the code you shown should crash even before you click on stuff.</p>
]]></description><link>https://forum.qt.io/post/663239</link><guid isPermaLink="true">https://forum.qt.io/post/663239</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 03 Jun 2021 14:24:43 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Thu, 03 Jun 2021 12:20:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> Ok thank you for your feedback. Here is what I have done:</p>
<p dir="auto">ConfigurationDialog::ConfigurationDialog(QWidget* parent)<br />
: QDialog(parent)<br />
{<br />
ui.setupUi(this);<br />
setWindowFlags(Qt::WindowStaysOnTopHint);</p>
<pre><code>ui.listWidget-&gt;addItem("Text1");
ui.listWidget-&gt;addItem("Text2");
ui.listWidget-&gt;addItem("Text3");
ui.listWidget-&gt;addItem("Text4");
ui.listWidget-&gt;addItem("Text5");

item1Configuration* item1 = new item1Configuration;
item2Configuration* item2 = new item2Configuration;
item3Configuration* item3 = new item3Configuration;
item4Configuration* item4 = new item4Configuration;
item5Configuration* item5 = new item5Configuration;

ui.stackedWidget-&gt;addWidget(item1);
ui.stackedWidget-&gt;addWidget(item2);
ui.stackedWidget-&gt;addWidget(item3);
ui.stackedWidget-&gt;addWidget(item4);
ui.stackedWidget-&gt;addWidget(item5);


connect(ui.listWidget, SIGNAL(itemClicked(QListWidgetItem*)),
	this, SLOT(onListItemClicked(QListWidgetItem*)));
</code></pre>
<p dir="auto">}</p>
<p dir="auto">ConfigurationDialog::~ConfigurationDialog()<br />
{<br />
}</p>
<p dir="auto">void ConfigurationDialog::onListItemClicked(QListWidgetItem* item)<br />
{<br />
ui.stackedWidget-&gt;setCurrentIndex(ui.listWidget-&gt;currentRow());<br />
}</p>
<p dir="auto">Now I think the logic is correct (I have also implemented the SIGNAL/CONTROL as you suggested). The problem is that the application does not open anymore when I compile. Instead after a little bit of waiting a window opens up with the following error:</p>
<p dir="auto">Unhandled exception at 0x00007FFD5793B866 (ntdll.dll) in Application.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x000000190E003FF8).</p>
]]></description><link>https://forum.qt.io/post/663217</link><guid isPermaLink="true">https://forum.qt.io/post/663217</guid><dc:creator><![CDATA[TommyTLC]]></dc:creator><pubDate>Thu, 03 Jun 2021 12:20:40 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Wed, 02 Jun 2021 18:20:16 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">As <a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a> suggests, you will have to write some code yourself. Designer does not generate anything code wise with regard to interaction.</p>
<p dir="auto">You can click all you want on the items of your QListWidget, it will have no effect on the QStackedWidget.</p>
<p dir="auto">You have to implement a slot that will switch the QStackedWidget current widget based on the item you clicked.</p>
]]></description><link>https://forum.qt.io/post/663120</link><guid isPermaLink="true">https://forum.qt.io/post/663120</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 02 Jun 2021 18:20:16 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Wed, 02 Jun 2021 18:14:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tommytlc">@<bdi>TommyTLC</bdi></a></p>
<p dir="auto">You haven't read the signal &amp; slot doc?! It probably helps you to understand the mechanism better.</p>
<p dir="auto">A slot is pretty much a function that is called every time you "fire" (emit) the signal.<br />
So you could make a connection to show the correct page of your stackedWidget depending on which item or button you click.</p>
]]></description><link>https://forum.qt.io/post/663118</link><guid isPermaLink="true">https://forum.qt.io/post/663118</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Wed, 02 Jun 2021 18:14:23 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Wed, 02 Jun 2021 15:19:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a> My arincWidget.ui has layouts, yes. The show() actually shows the widget exactly where I want it, but yes I need to find a more stable and organized way of instantiating it. As you said the solution is probably using signals and slots. In this case the signal would be the item in the list and the slot the arincWidget.ui instantiation, correct?</p>
]]></description><link>https://forum.qt.io/post/663078</link><guid isPermaLink="true">https://forum.qt.io/post/663078</guid><dc:creator><![CDATA[TommyTLC]]></dc:creator><pubDate>Wed, 02 Jun 2021 15:19:05 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Wed, 02 Jun 2021 13:21:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tommytlc">@<bdi>TommyTLC</bdi></a> said in <a href="/post/663064">Filling StackedWidgets</a>:</p>
<blockquote>
<p dir="auto">arincWidget-&gt;show();</p>
</blockquote>
<p dir="auto">Showing the <code>arincWidget</code> does not help in your case. You want to show the stackedWidget page with the widget, not the widget itself right?</p>
<blockquote>
<p dir="auto">Now I need to understand how to have it only show up when the first item is selected inside the dialog's list.</p>
</blockquote>
<p dir="auto">You can flip the pages according to your clicked items using signals &amp; slots.</p>
<ul>
<li><a href="https://doc.qt.io/qt-5/signalsandslots.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/signalsandslots.html</a></li>
</ul>
<p dir="auto">Edit:</p>
<p dir="auto">Do you have any layout in your UI?</p>
]]></description><link>https://forum.qt.io/post/663066</link><guid isPermaLink="true">https://forum.qt.io/post/663066</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Wed, 02 Jun 2021 13:21:39 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Wed, 02 Jun 2021 12:54:34 GMT]]></title><description><![CDATA[<p dir="auto">UPDATE: I managed to show the Item1.ui file simply by adding:</p>
<p dir="auto">Arinc424Configuration* arincWidget = new Arinc424Configuration();<br />
ui.stackedWidget-&gt;addWidget(arincWidget);<br />
<strong>arincWidget-&gt;show();</strong></p>
<p dir="auto">In the dialog.cpp file. Now I need to understand how to have it only show up when the first item is selected inside the dialog's list.</p>
]]></description><link>https://forum.qt.io/post/663064</link><guid isPermaLink="true">https://forum.qt.io/post/663064</guid><dc:creator><![CDATA[TommyTLC]]></dc:creator><pubDate>Wed, 02 Jun 2021 12:54:34 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Wed, 02 Jun 2021 12:32:31 GMT]]></title><description><![CDATA[<p dir="auto">Also I forgot to add that StackWidget has as many pages as the number of items in the list to the left. If I go into the ui_dialog.h file and manually add Item1 from there it shows up as I want to. The problem is of course that nothing saves in that ui_dialog.h file after I close and reopen the solution.</p>
]]></description><link>https://forum.qt.io/post/663059</link><guid isPermaLink="true">https://forum.qt.io/post/663059</guid><dc:creator><![CDATA[TommyTLC]]></dc:creator><pubDate>Wed, 02 Jun 2021 12:32:31 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Wed, 02 Jun 2021 12:28:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pl45m4">@<bdi>Pl45m4</bdi></a> This is what my dialog.ui looks like:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/9a450b0b-1030-4281-b428-25beb0678a8d.PNG" alt="ui.PNG" class=" img-fluid img-markdown" /></p>
<p dir="auto">My Item1 is a Qwidget Class.</p>
]]></description><link>https://forum.qt.io/post/663058</link><guid isPermaLink="true">https://forum.qt.io/post/663058</guid><dc:creator><![CDATA[TommyTLC]]></dc:creator><pubDate>Wed, 02 Jun 2021 12:28:43 GMT</pubDate></item><item><title><![CDATA[Reply to Filling StackedWidgets on Wed, 02 Jun 2021 12:19:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tommytlc">@<bdi>TommyTLC</bdi></a></p>
<p dir="auto">How does your (G)UI for your dialog look like? What type of class is <code>Item1</code>?</p>
]]></description><link>https://forum.qt.io/post/663055</link><guid isPermaLink="true">https://forum.qt.io/post/663055</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Wed, 02 Jun 2021 12:19:37 GMT</pubDate></item></channel></rss>