<?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[Cannot delete items of a QVBoxLayout]]></title><description><![CDATA[<p dir="auto">Hi!<br />
this is in the constructor:</p>
<pre><code>myGroupBox-&gt;setLayout(myBoxLayout);
myBoxLayout-&gt;setAlignment(Qt::AlingTop);
</code></pre>
<p dir="auto">and then I call this:</p>
<pre><code>if(myBoxLayout-&gt;takeAt(0) != NULL){
    QLayoutItem *item;
    while((item = myBoxLayout-&gt;takeQt(0)) != NULL){
        delete item-&gt;widget();
        delete item;
    }
}
</code></pre>
<p dir="auto">to remove all widgets from the layout.<br />
The program just crashes. What did I miss?<br />
This code came from this thread, but I can't find a answer for my problem there:<br />
<a href="https://stackoverflow.com/questions/4272196/qt-remove-all-widgets-from-layout" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/4272196/qt-remove-all-widgets-from-layout</a><br />
Thanks for answers</p>
]]></description><link>https://forum.qt.io/topic/82341/cannot-delete-items-of-a-qvboxlayout</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 11:46:09 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/82341.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 13 Aug 2017 14:07:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 15:15:06 GMT]]></title><description><![CDATA[<p dir="auto">Ahh about 1300 lines, unfortunately not small.<br />
It works now... aaand yes, I think the deleting of the builddirectory worked.<br />
What happened:<br />
I deleted the build directory and then the program crashed at an other point before the setting up of the layout. I found a thing that I would not call a mistake, but it surely is in some way, because of my endless function calling, the function, where I set up the layouts got called twice. I don't really know, why this is a mistake, but after I fixed it, it worked and then the program was able to say that it is a nullpointer. So I changed it back to new QVBoxLayout and everything works.<br />
The weird thing is, that I really don't know why it was a problem to setting up the layout as a nullpointer twice.<br />
But, anyway, thanks for your help!</p>
]]></description><link>https://forum.qt.io/post/410146</link><guid isPermaLink="true">https://forum.qt.io/post/410146</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Sun, 13 Aug 2017 15:15:06 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 15:18:14 GMT]]></title><description><![CDATA[<p dir="auto">Super :)<br />
Im not sure what calling the function twice could be issue but it did do something it seems.</p>
]]></description><link>https://forum.qt.io/post/410148</link><guid isPermaLink="true">https://forum.qt.io/post/410148</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sun, 13 Aug 2017 15:18:14 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 15:15:06 GMT]]></title><description><![CDATA[<p dir="auto">Ahh about 1300 lines, unfortunately not small.<br />
It works now... aaand yes, I think the deleting of the builddirectory worked.<br />
What happened:<br />
I deleted the build directory and then the program crashed at an other point before the setting up of the layout. I found a thing that I would not call a mistake, but it surely is in some way, because of my endless function calling, the function, where I set up the layouts got called twice. I don't really know, why this is a mistake, but after I fixed it, it worked and then the program was able to say that it is a nullpointer. So I changed it back to new QVBoxLayout and everything works.<br />
The weird thing is, that I really don't know why it was a problem to setting up the layout as a nullpointer twice.<br />
But, anyway, thanks for your help!</p>
]]></description><link>https://forum.qt.io/post/410146</link><guid isPermaLink="true">https://forum.qt.io/post/410146</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Sun, 13 Aug 2017 15:15:06 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 15:06:56 GMT]]></title><description><![CDATA[<p dir="auto">I agree @Wieland , the big question is just Where :)</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/niagarer">@<bdi>Niagarer</bdi></a><br />
If its a small project, can you zip and link it here ?</p>
]]></description><link>https://forum.qt.io/post/410145</link><guid isPermaLink="true">https://forum.qt.io/post/410145</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sun, 13 Aug 2017 15:06:56 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 15:01:20 GMT]]></title><description><![CDATA[<p dir="auto">I say "unitialized memory <em>somewhere</em>".</p>
]]></description><link>https://forum.qt.io/post/410142</link><guid isPermaLink="true">https://forum.qt.io/post/410142</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sun, 13 Aug 2017 15:01:20 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 15:00:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
Yep, this project works. So it has to be my bad.</p>
]]></description><link>https://forum.qt.io/post/410141</link><guid isPermaLink="true">https://forum.qt.io/post/410141</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Sun, 13 Aug 2017 15:00:34 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:58:23 GMT]]></title><description><![CDATA[<p dir="auto">Ok, I did and now I have a mistake at a point in the code before the setting up of the layout.<br />
I add a Tab of a tabWidget and there it crashes.,.. This was never a problem, this line works sonce weeks, I did not change anything there.<br />
I deleted the build directory, opened creator again, ran qmake, rebuilt and that's it, no errors, it is just crashing</p>
]]></description><link>https://forum.qt.io/post/410140</link><guid isPermaLink="true">https://forum.qt.io/post/410140</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:58:23 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:46:55 GMT]]></title><description><![CDATA[<p dir="auto">Close Creator, delete the build directory and start Creator again. Sometime strange things happen.</p>
]]></description><link>https://forum.qt.io/post/410139</link><guid isPermaLink="true">https://forum.qt.io/post/410139</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:46:55 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:45:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
Now, it does not print any qDebugs() anymore... what the hell!?</p>
]]></description><link>https://forum.qt.io/post/410138</link><guid isPermaLink="true">https://forum.qt.io/post/410138</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:45:34 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:44:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/niagarer">@<bdi>Niagarer</bdi></a><br />
Hi, no worries, we all do stupid mistakes sometimes.<br />
Its a sign of a productive programmer ;)</p>
<p dir="auto">first<br />
QVBoxLayout *myBoxLayout; -&gt;     QVBoxLayout *myBoxLayout=nullptr.<br />
in .h<br />
then do NOT<br />
myBoxLayout = nullptr; before the check. ( you kill it )</p>
<p dir="auto">also , it must print something ???<br />
myBoxLayout = nullptr;<br />
if(myBoxLayout == nullptr){<br />
qDebug() &lt;&lt; "layout is null";<br />
}<br />
else something is really, really wrong.</p>
<p dir="auto">Can you test this small sample ?<br />
<a href="https://www.dropbox.com/s/tkl1hdik6q0qwl2/myreuselayout.zip?dl=0" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.dropbox.com/s/tkl1hdik6q0qwl2/myreuselayout.zip?dl=0</a><br />
Uses your code to remove buttons from layout.</p>
]]></description><link>https://forum.qt.io/post/410137</link><guid isPermaLink="true">https://forum.qt.io/post/410137</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:44:42 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:45:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
In the .h file:</p>
<pre><code>    QVBoxLayout *myBoxLayout;
</code></pre>
<p dir="auto">and in the .cpp file:</p>
<pre><code>myBoxLayout = nullptr;
if(myBoxLayout == nullptr){
    qDebug() &lt;&lt; "layout is null";
}
</code></pre>
<p dir="auto">and it prints nothing...<br />
I really don't understand that too.<br />
I just hope that I am not doing a totally dumb mistake here...</p>
]]></description><link>https://forum.qt.io/post/410136</link><guid isPermaLink="true">https://forum.qt.io/post/410136</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:45:41 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:38:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/niagarer">@<bdi>Niagarer</bdi></a><br />
what ??<br />
myBoxLayout = nullptr;<br />
if(myBoxLayout != nullptr){<br />
qDebug() &lt;&lt; "layout is not null";<br />
}</p>
<p dir="auto">that code should say nothing. :)<br />
I assume that<br />
myBoxLayout = nullptr; &lt;&lt;&lt; in .h yes ?</p>
<p dir="auto">Sorry, i have really no idea.<br />
Its does work that way and i have used takeAt many times.</p>
]]></description><link>https://forum.qt.io/post/410135</link><guid isPermaLink="true">https://forum.qt.io/post/410135</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:38:19 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:35:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
Ok, I tried it.<br />
I did not make the classic mistake but if I define it with a nullpointer</p>
<pre><code>myBoxLayout = nullptr;
</code></pre>
<p dir="auto">and then asking if it's nullptr where I try to delete all content, it says, it is not null<br />
But I only defined it once...<br />
And if I ask that this way:</p>
<pre><code>myBoxLayout = nullptr;
if(myBoxLayout != nullptr){
    qDebug() &lt;&lt; "layout is not null";
}
</code></pre>
<p dir="auto">it says, it is not null...</p>
]]></description><link>https://forum.qt.io/post/410134</link><guid isPermaLink="true">https://forum.qt.io/post/410134</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:35:57 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:29:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/niagarer">@<bdi>Niagarer</bdi></a><br />
If it crashes there, something must be wrong with the pointer<br />
myBoxLayout-&gt;count();</p>
<p dir="auto">You did show real code, yes ?</p>
<p dir="auto">A classic is to define in .h<br />
and then do<br />
QVBoxLayout *myBoxLayout = new QVBoxLayout;  ( in ctror)<br />
and make local variable instead.</p>
<p dir="auto">set it to null where u define it<br />
QVBoxLayout *myBoxLayout=nullptr;</p>
<p dir="auto">and check if its NON null before using it on the count()</p>
]]></description><link>https://forum.qt.io/post/410131</link><guid isPermaLink="true">https://forum.qt.io/post/410131</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:29:04 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:26:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
Thanks, I tried and it crashes at exactely this line you gave me.<br />
I can not do anything with the layout<br />
Seems to be a nasty one...</p>
]]></description><link>https://forum.qt.io/post/410129</link><guid isPermaLink="true">https://forum.qt.io/post/410129</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:26:12 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:22:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/niagarer">@<bdi>Niagarer</bdi></a><br />
Cant guess then.</p>
<p dir="auto">try<br />
qDebug() &lt;&lt;  "items:" &lt;&lt; myBoxLayout-&gt;count();<br />
just before the If.</p>
]]></description><link>https://forum.qt.io/post/410127</link><guid isPermaLink="true">https://forum.qt.io/post/410127</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:22:01 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:19:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
Nope, this  is a class attribute and in the constructor (all in the same class) I do</p>
<pre><code>myBoxLayout = new QVBoxLayout;
</code></pre>
<p dir="auto">and there is also no error, that works.</p>
]]></description><link>https://forum.qt.io/post/410126</link><guid isPermaLink="true">https://forum.qt.io/post/410126</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:19:49 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:17:22 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
It crashes at<br />
if(myBoxLayout-&gt;takeAt(0) .. ?</p>
<p dir="auto">did you forget to new myBoxLayout ?</p>
]]></description><link>https://forum.qt.io/post/410125</link><guid isPermaLink="true">https://forum.qt.io/post/410125</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:17:22 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:15:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
on the line with the if statement</p>
]]></description><link>https://forum.qt.io/post/410124</link><guid isPermaLink="true">https://forum.qt.io/post/410124</guid><dc:creator><![CDATA[Niagarer]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:15:49 GMT</pubDate></item><item><title><![CDATA[Reply to Cannot delete items of a QVBoxLayout on Sun, 13 Aug 2017 14:12:42 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
Seems ok but there some notes</p>
<pre><code>
if(myBoxLayout-&gt;takeAt(0) != NULL){ &lt;&lt; you take first out first here ( and do not delete it)
    QLayoutItem *item;
    while((item = myBoxLayout-&gt;takeQt(0)) != NULL){
        delete item-&gt;widget();
        delete item;
    }
}
</code></pre>
<p dir="auto">IF you single step , what lines does it crash on ?</p>
]]></description><link>https://forum.qt.io/post/410123</link><guid isPermaLink="true">https://forum.qt.io/post/410123</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Sun, 13 Aug 2017 14:12:42 GMT</pubDate></item></channel></rss>