<?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[QVector&lt; QVBoxLayout * &gt; crashing on adding layout]]></title><description><![CDATA[<p dir="auto">I'm trying to make a QStackedWidget with 5 labels and text inputs on each of the 10 pages. Like this: <img src="https://ddgobkiprc33d.cloudfront.net/11bda2e6-8551-4ad2-8b29-34b314d4aa59.png" alt="Screenshot_1.png" class=" img-fluid img-markdown" /><br />
So far I've got:</p>
<pre><code>    int ss=0, s=0;
    ui-&gt;stck-&gt;setCurrentIndex(0);
    QVector&lt; QWidget * &gt; wdgVector(10);
    QVector&lt; QVBoxLayout * &gt; strVector(10);
    for (int i=0; i&lt;50; i++){
        if (5&lt;=s)
        {
            wdgVector[ss]-&gt;setLayout(strVector[ss]);
            ui-&gt;stck-&gt;insertWidget(ss, wdgVector[ss]);
            ss++;
            s=0;
        }
        QLabel *lbl = new QLabel(this);
        QHBoxLayout *hlay = new QHBoxLayout();
        QLineEdit *txt = new QLineEdit(this);
        hlay-&gt;addWidget(lbl);
        hlay-&gt;addWidget(txt);
        s++;
        strVector[ss]-&gt;addLayout(hlay);//&lt;----CRASH
    }
</code></pre>
<p dir="auto">It's crashing on the last bit of code and I'm unsure how to fix it.</p>
]]></description><link>https://forum.qt.io/topic/120171/qvector-qvboxlayout-crashing-on-adding-layout</link><generator>RSS for Node</generator><lastBuildDate>Thu, 23 Apr 2026 11:59:57 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/120171.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 21 Oct 2020 12:29:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QVector&lt; QVBoxLayout * &gt; crashing on adding layout on Thu, 22 Oct 2020 06:54:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/inzinejkr">@<bdi>Inzinejkr</bdi></a><br />
I can only say: start by creating <em>separate</em> instances of all your <code>QVBoxLayout</code>s: a given instance must only be used as a layout for a widget <em>once</em>, not re-used for multiple widgets as you presently show in your code.</p>
]]></description><link>https://forum.qt.io/post/623546</link><guid isPermaLink="true">https://forum.qt.io/post/623546</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 22 Oct 2020 06:54:23 GMT</pubDate></item><item><title><![CDATA[Reply to QVector&lt; QVBoxLayout * &gt; crashing on adding layout on Wed, 21 Oct 2020 15:52:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/623449">QVector&lt; QVBoxLayout * &gt; crashing on adding layout</a>:</p>
<blockquote>
<p dir="auto">You are creating multiple <code>QGroupBox</code>es in your loop, yet you set each one to have the <em>same</em> <code>QVBoxLayout *vertical = new QVBoxLayout;</code> instance.  <em>And</em> you later do <code>page-&gt;setLayout(vertical);</code>.  Something wrong here!</p>
</blockquote>
<p dir="auto">Well, I guess? I'm trying to group up one label and one textbox..<br />
<img src="https://ddgobkiprc33d.cloudfront.net/cf539c4a-01bc-48c0-8532-e022dfee1ddd.png" alt="Screenshot_2.png" class=" img-fluid img-markdown" /><br />
So this, just via code</p>
]]></description><link>https://forum.qt.io/post/623464</link><guid isPermaLink="true">https://forum.qt.io/post/623464</guid><dc:creator><![CDATA[Inzinejkr]]></dc:creator><pubDate>Wed, 21 Oct 2020 15:52:10 GMT</pubDate></item><item><title><![CDATA[Reply to QVector&lt; QVBoxLayout * &gt; crashing on adding layout on Wed, 21 Oct 2020 15:00:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/inzinejkr">@<bdi>Inzinejkr</bdi></a> said in <a href="/post/623446">QVector&lt; QVBoxLayout * &gt; crashing on adding layout</a>:</p>
<blockquote>
<p dir="auto">grp-&gt;setLayout(vertical);</p>
</blockquote>
<p dir="auto">You are creating multiple <code>QGroupBox</code>es in your loop, yet you set each one to have the <em>same</em> <code>QVBoxLayout *vertical = new QVBoxLayout;</code> instance.  <em>And</em> you later do <code>page-&gt;setLayout(vertical);</code>.  Something wrong here!</p>
]]></description><link>https://forum.qt.io/post/623449</link><guid isPermaLink="true">https://forum.qt.io/post/623449</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 21 Oct 2020 15:00:50 GMT</pubDate></item><item><title><![CDATA[Reply to QVector&lt; QVBoxLayout * &gt; crashing on adding layout on Wed, 21 Oct 2020 14:48:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> said in <a href="/post/623430">QVector&lt; QVBoxLayout * &gt; crashing on adding layout</a>:</p>
<blockquote>
<p dir="auto">(untested pseudocode ;-))</p>
</blockquote>
<p dir="auto">Alright, it does what I wanted, so good job! :)<br />
Just for the beauty I thought about inserting the label and text input in a group box, but I can't get that to work neither.</p>
<pre><code>    int z=0;

    for (int i = 0; i &lt; 3; i++) {
    QVBoxLayout *vertical = new QVBoxLayout;
    for (int y = 0; y &lt; 5; y++) {
        QGroupBox *grp=new QGroupBox();
        QVBoxLayout *vlay=new QVBoxLayout;
        grp-&gt;setTitle("Something number: "+QString::number(z));
        vlay-&gt;addWidget(new QLabel("Label number: ("+QString::number(z)));
        vlay-&gt;addWidget(new QLineEdit);
        vertical-&gt;addLayout(vlay);
        grp-&gt;setLayout(vertical);
        z++;
      }
      QWidget *page = new QWidget;
      page-&gt;setLayout(vertical);
      ui-&gt;stck-&gt;insertWidget(i, page);
      ui-&gt;stck-&gt;setCurrentIndex(0);
    }
</code></pre>
<p dir="auto">Sorry for bothering you..</p>
]]></description><link>https://forum.qt.io/post/623446</link><guid isPermaLink="true">https://forum.qt.io/post/623446</guid><dc:creator><![CDATA[Inzinejkr]]></dc:creator><pubDate>Wed, 21 Oct 2020 14:48:18 GMT</pubDate></item><item><title><![CDATA[Reply to QVector&lt; QVBoxLayout * &gt; crashing on adding layout on Wed, 21 Oct 2020 12:46:11 GMT]]></title><description><![CDATA[<pre><code>QStackedWidget *parent = ... something;
for (int i = 0; i &lt; 10; ++i) {
  QVBoxLayout *vertical = new QVBoxLayout;
  for (int y = 0; y &lt; 5; ++y) {
    QHBoxLayout *row = new QHBoxLayout;
    row-&gt;addWidget(new QLabel(tr("TextLabel")));
    row-&gt;addWidget(new QLineEdit);
    vertical-&gt;addLayout(row);
  }
  QWidget *page = new QWidget;
  page-&gt;setLayout(vertical);
  parent-&gt;addWidget(page);
}
</code></pre>
<p dir="auto">(untested pseudocode ;-))</p>
]]></description><link>https://forum.qt.io/post/623430</link><guid isPermaLink="true">https://forum.qt.io/post/623430</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Wed, 21 Oct 2020 12:46:11 GMT</pubDate></item><item><title><![CDATA[Reply to QVector&lt; QVBoxLayout * &gt; crashing on adding layout on Wed, 21 Oct 2020 12:42:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/inzinejkr">@<bdi>Inzinejkr</bdi></a></p>
<pre><code>wdgVector[ss] = new QWidget();
wdgVector[ss]-&gt;setLayout(strVector[ss]);
</code></pre>
<p dir="auto">But you also have to initialise strVector.</p>
<pre><code>QVector&lt; QVBoxLayout * &gt; strVector(10); // This only declares a vector containing pointers - you have to create actual objects and put their pointers there. C++ basics.
</code></pre>
]]></description><link>https://forum.qt.io/post/623428</link><guid isPermaLink="true">https://forum.qt.io/post/623428</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 21 Oct 2020 12:42:06 GMT</pubDate></item><item><title><![CDATA[Reply to QVector&lt; QVBoxLayout * &gt; crashing on adding layout on Wed, 21 Oct 2020 12:37:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> said in [QVector&lt; QVBoxLayout * &gt; crashing on adding layout]</p>
<blockquote>
<p dir="auto">You never insert any value into <code>strVector</code>.</p>
</blockquote>
<p dir="auto">So how would I do that to achieve the image shown?</p>
]]></description><link>https://forum.qt.io/post/623427</link><guid isPermaLink="true">https://forum.qt.io/post/623427</guid><dc:creator><![CDATA[Inzinejkr]]></dc:creator><pubDate>Wed, 21 Oct 2020 12:37:05 GMT</pubDate></item><item><title><![CDATA[Reply to QVector&lt; QVBoxLayout * &gt; crashing on adding layout on Wed, 21 Oct 2020 12:34:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/inzinejkr">@<bdi>Inzinejkr</bdi></a> said in <a href="/post/623423">QVector&lt; QVBoxLayout * &gt; crashing on adding layout</a>:</p>
<blockquote>
<p dir="auto">strVector[ss]-&gt;addLayout(hlay);//&lt;----CRASH</p>
</blockquote>
<p dir="auto">You never insert any value into <code>strVector</code>. The vector is empty so it will always crash when you try to access an element of it.</p>
]]></description><link>https://forum.qt.io/post/623426</link><guid isPermaLink="true">https://forum.qt.io/post/623426</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Wed, 21 Oct 2020 12:34:39 GMT</pubDate></item></channel></rss>