<?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[Crash adding QVBoxLayout to QDialog]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I don't understand the problem why my program crashes when I try to add a new QVBoxLayout to my QDialog.</p>
<p dir="auto">This is my header:</p>
<pre><code>class myQDialog : public QDialog
{
    Q_OBJECT

private:
    QTabWidget *twMain;
    QWidget *tabDataOne, *tabDataTwo, *tabDataThree;
    QVBoxLayout *layDataOne, *layDataTwo, *layDataThree;

public:
    myQDialog(QWidget *parent = nullptr);
    ~myQDialog();
};
</code></pre>
<p dir="auto">And the source:</p>
<pre><code>myQDialog::myQDialog(QWidget *parent) : QDialog(parent)
{
    setWindowTitle("Setup");
    twMain = new QTabWidget(this);
    twMain-&gt;setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);

    tabDataOne = new QWidget(twMain);
    layDataOne = new QVBoxLayout;                 // &lt;--- program crashes here
    tabDataOne-&gt;setLayout(layDataOne);

/*
...
*/
}

myQDialog::~myQDialog()
{

}

</code></pre>
<p dir="auto">I can not explain where the problem is. I use the same code in my QMainWindow and there it works. Maybe there is a problem using it inside a QDialog?</p>
<p dir="auto">Thank you for your help in anticipation.</p>
<p dir="auto">Binary91</p>
]]></description><link>https://forum.qt.io/topic/139537/crash-adding-qvboxlayout-to-qdialog</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 10:11:35 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139537.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 24 Sep 2022 09:08:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Mon, 10 Oct 2022 08:13:03 GMT]]></title><description><![CDATA[<p dir="auto">Ok guys,<br />
thank you very much for your detailed help.</p>
<p dir="auto">Have a nice week!<br />
Binary</p>
]]></description><link>https://forum.qt.io/post/731996</link><guid isPermaLink="true">https://forum.qt.io/post/731996</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Mon, 10 Oct 2022 08:13:03 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Fri, 07 Oct 2022 13:28:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a><br />
Both the "green triangle buttons", so for <strong>Debug</strong> as well as <strong>Run</strong>, are the <em>good</em> ones here.  The "risky" one does not appear here, it is a "small" one on the Debugger window pane, don't worry about it, you have not shown it or used it.</p>
<p dir="auto">This means that <em>whichever</em> of the buttons you show <em>should be working fine</em>.  And that <em>does</em> mean: if you have changed any source code, <code>.cpp</code> or <code>.h</code>, it <em>SHOULD</em> do the same "Build" before running/debugging that you would do by pressing the "hammer" icon.</p>
<p dir="auto">If this is <em>not</em> happening for you, there is a problem....</p>
]]></description><link>https://forum.qt.io/post/731729</link><guid isPermaLink="true">https://forum.qt.io/post/731729</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 07 Oct 2022 13:28:50 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Fri, 07 Oct 2022 12:52:26 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> said in <a href="/post/731681">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">Is this really the button I should always use?</p>
</blockquote>
<p dir="auto">Only if you want to run your app through debugger.<br />
Else use the other one.</p>
<p dir="auto">"So, is it possible that the code compiles (with the dangerous green triangle on the top) and runs without invoking the make?" - make is always used to build your project (this is what the hammer button is doing: start make. It should also first execute qmake if you change your project files, but this is not always happening, that is why it is sometimes necessary to delete build folder).</p>
]]></description><link>https://forum.qt.io/post/731716</link><guid isPermaLink="true">https://forum.qt.io/post/731716</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Fri, 07 Oct 2022 12:52:26 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Fri, 07 Oct 2022 09:28:53 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/731034">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">Be careful, there are two "green triangle" buttons, and (as I discovered) they do not do quite the same thing.  The "bigger" one, where you have Run and Debug buttons, is where to press, they cause recompile-before-run.  But there is also a "smaller" one, on the debugging pane toolbar along with some other small buttons.  This is a dangerous one!  It causes re-run, but deliberately does not recompile.  It repeats the last run with what you already have compiled, and basically should "never" be used!<br />
But if you are using the right Run button you should always find it does the Build action first, in case things aren't up-to-date.  And you can see its action/output in the Compiler output tab.</p>
</blockquote>
<p dir="auto">Sorry for the belated response.<br />
Ok, well, just to be safe that we're talking about the same stuff:<br />
Overview of the action buttons on the left bottom corner of QtCreator (I'm using a german version, so maybe my translations are not 100 % identical to yours):<br />
<img src="https://ddgobkiprc33d.cloudfront.net/d0d5d33b-0c6a-458e-835d-1c81e91d9c41.png" alt="Buttons overview.png" class=" img-fluid img-markdown" /><br />
The first "button" lets me decide the mode, right? I can choose from 3 modes, Debug, Profile and Release:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/9ad066af-63dd-4143-8050-0e975d6a1d28.png" alt="Button top.png" class=" img-fluid img-markdown" /><br />
I always use the Debug mode, because it was pre-setted :-)<br />
The next button is the "Run" button:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/37c25e3f-d6e3-434d-abd3-70ccd3b4972c.png" alt="Button middle.png" class=" img-fluid img-markdown" /><br />
I guess this is the dangerous button you mentioned, right? BUT, this is the button I usually use when I change my code, and till now, it always worked (except creating new Q_OBJECT macros or except this special issue we discussed in this topic). I also get errors/warnings in the compiler output window with it. So why do you say it just runs the project without compiling?<br />
The button next to it is maybe the button you recommed to use instead, right?<br />
<img src="https://ddgobkiprc33d.cloudfront.net/0e46607c-feeb-4272-8004-586775cca478.png" alt="Button middle-down.png" class=" img-fluid img-markdown" /><br />
Well, using this button starts a full debugging of the code, it takes long time and I have to go step by step through the code. Then, lots of different output windows are shown like the stack (I already posted that earlier as you recommended) or a debugger window. Is this really the button I should always use? Sounds very time- and energy consuming...<br />
The button on the bottom with the hammer is the build project button, this is what I use when I create new classes with modifications to the MOC system:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/0b4df232-487f-4123-900c-c0edce70beaf.png" alt="Button down.png" class=" img-fluid img-markdown" /><br />
But none of those buttons helped me with my issue in this topic. Instead, I had to completely remove the build directory...</p>
<p dir="auto">"<em>I should/may well be necessary to recompile if you change a header file. Indeed it is vital, e.g. if you change variable declarations, as you have seen. But you should not need to take some explicit action for that to happen. When you Build or Run, Qt Creator should invoke the make system for you, and that should recompile as required. As I say, check the Compiler Output tab.<br />
If either the make is not being invoked or it does not cause all object files which depend on the changed header file to be recompiled then you have a problem/something wrong.</em>"</p>
<p dir="auto">So, is it possible that the code compiles (with the dangerous green triangle on the top) and runs without invoking the <strong>make</strong>? Otherwise I cannot understand how I could create and modify simple projects in the past with only using this button...</p>
]]></description><link>https://forum.qt.io/post/731681</link><guid isPermaLink="true">https://forum.qt.io/post/731681</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Fri, 07 Oct 2022 09:28:53 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Sun, 02 Oct 2022 08:40:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> said in <a href="/post/731033">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">I always just pushed the green triangle button</p>
</blockquote>
<p dir="auto">Be careful, there are <em>two</em> "green triangle" buttons, and (as I discovered) they do not do quite the same thing.  The "bigger" one, where you have <strong>Run</strong> and <strong>Debug</strong> buttons, is where to press, they cause recompile-before-run.  But there is also a "smaller" one, on the debugging pane toolbar along with some other small buttons.  This is a dangerous one!  It causes re-run, but deliberately does <em>not</em> recompile.  It repeats the last run with what you already have compiled, and basically should "never" be used!</p>
<p dir="auto">But if you are using the right <strong>Run</strong> button you should always find it does the <strong>Build</strong> action first, in case things aren't up-to-date.  And you can see its action/output in the <strong>Compiler</strong> output tab.</p>
<blockquote>
<p dir="auto">It should not be neccessary to re-build everything each time I change something in the headers?</p>
</blockquote>
<p dir="auto">I should/may well be necessary to recompile if you change a header file.  Indeed it is vital, e.g. if you change variable declarations, as you have seen.  <em>But</em> you should not need to <em>take some explicit action</em> for that to happen.  When you <strong>Build</strong> <em>or</em> <strong>Run</strong>, Qt <strong>Creator</strong> should invoke the <strong>make</strong> system for you, and that should recompile as required.  As I say, check the <strong>Compiler Output</strong> tab.</p>
<p dir="auto">If either the <strong>make</strong> is not being invoked or it does not cause all object files which depend on the changed header file to be recompiled then you have a problem/something wrong.</p>
]]></description><link>https://forum.qt.io/post/731034</link><guid isPermaLink="true">https://forum.qt.io/post/731034</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 02 Oct 2022 08:40:51 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Sun, 02 Oct 2022 08:31:17 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/730783">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">100% yes!  If you change anything about member variables --- order, size, type --- you must rebuild.  And you must rebuild the object files of any other files which use that class too.  The C++ compiler generates code which accesses class members by their offset within the class, and if anything "moves" disaster will strike if any object file does not know about this<br />
I cannot believe you have changed order in the past and not recompiled.</p>
</blockquote>
<p dir="auto">Well, what do you understand under <code>recompiling</code>? In the past, after changing header files (or source code) I always just pushed the green triangle button in the QtCreator ("compile &amp; run") and the code was "recompiled". But there is another button with the hammer, the "build" button. This button is what I used when I created new classes that have the Q_OBJECT macro because of the <code>moc</code> files.<br />
I always had good experience with this, until now. BUT, neigther just recompiling, nor rebuilding my project in this case had a positive effect. Instead, only completely deleting the build directory and completely re-building, compiling and running the program worked. Can you tell me, why?</p>
<p dir="auto">"<em>The make system you use should have the object files as dependencies of the .h files. When you change a .h file it should see the timestamp change and know to recompile at minimum everything which uses that .h file. You should not have to tell it to do so.</em>"<br />
So you agree to what I just said? It should not be neccessary to re-build everything each time I change something in the headers?</p>
<p dir="auto">"<em>If I were you I would verify this behaviour now: if you make any change in myQDialogUseraccountRegistrationSetup.h what does and does not get recompiled?</em>"<br />
I'll try it changing something line by line and simply compile it. Let's see what happens...</p>
]]></description><link>https://forum.qt.io/post/731033</link><guid isPermaLink="true">https://forum.qt.io/post/731033</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Sun, 02 Oct 2022 08:31:17 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Fri, 30 Sep 2022 08:22:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> said in <a href="/post/730765">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">I completely deleted the build directory, built the project again and it works without changing anything of the code...</p>
</blockquote>
<p dir="auto">Well that is good news!  From experience, if something really inexplicable is happening when you try to build your code (unintelligible error messages) or when you run your code (the very odd behaviour you were reporting) it is worth doing a complete delete-and-rebuild in case that is the issue.</p>
<blockquote>
<p dir="auto">That is interesting, because in the past, I never had to do that and I (really, really often) changed the positions of class members inside the class declaration.<br />
So I have to re-build the project now each time I change anything inside a header file, like modifing member orders in the declaration list?</p>
</blockquote>
<p dir="auto">100% yes!  If you change anything about member variables --- order, size, type --- you <em>must</em> rebuild.  And you must rebuild the object files of any <em>other</em> files which use that class too.  The C++ compiler generates code which accesses class members by their offset within the class, and if anything "moves" disaster will strike if any object file does not know about this</p>
<p dir="auto">I cannot believe you have changed order in the past and not recompiled.  More to the point, how could it <em>not</em> have recompiled?  The <strong>make</strong> system you use should have the object files as dependencies of the <code>.h</code> files.  When you change a <code>.h</code> file it should see the timestamp change and know to recompile at minimum everything which uses that <code>.h</code> file.  You should not have to tell it to do so.  If I were you I would verify this behaviour now: if you make any change in <code>myQDialogUseraccountRegistrationSetup.h</code> what does and does not get recompiled?</p>
]]></description><link>https://forum.qt.io/post/730783</link><guid isPermaLink="true">https://forum.qt.io/post/730783</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 30 Sep 2022 08:22:22 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Fri, 30 Sep 2022 03:57:07 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/730632">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">One thing: when you change the order of member variables it is vital that all modules using the class be recompiled.  Make sure you delete all files in the build output (not source!) directory, re-run qmake, re-run the build.  It would also be interesting to test whether if you compile for release versus for debug the behaviour changes?</p>
</blockquote>
<p dir="auto">Wow, that did the job! I completely deleted the build directory, built the project again and it works without changing anything of the code...</p>
<p dir="auto">That is interesting, because in the past, I never had to do that and I (really, really often) changed the positions of class members inside the class declaration. I never had such an issue before. Maybe I just had luck till now...</p>
<p dir="auto">So I have to re-build the project now each time I change anything inside a header file, like modifing member orders in the declaration list?</p>
]]></description><link>https://forum.qt.io/post/730765</link><guid isPermaLink="true">https://forum.qt.io/post/730765</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Fri, 30 Sep 2022 03:57:07 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Thu, 29 Sep 2022 07:31:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> said in <a href="/post/730625">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">As I mentioned earlier, even only declaring the <code>layMain</code> inside the header causes the crash, when I declare it at the first position of all my layouts inside the class declaration. When I put it at the end of the member declarations and do not define it inside the .cpp, then it will not crash...</p>
</blockquote>
<p dir="auto">Hmmm....  In itself, C++ does not care what order you declare your member variables, nor how many you have.  Moving them around should have no effect.  <em>However</em>: when you create an instance of a class the member variables' area is <em>uninitialized</em>, the variables contain "random" data.  And <em>what</em> random value each one contains can indeed be affected by the "coincidences" of where they happen to be in memory, different position =&gt; different value.  Or same can happen if your code (somehow) "overruns"/"underruns" and writes into the instance's variables' storage area....</p>
<p dir="auto">One thing: when you change the order of member variables it is <em>vital</em> that <em>all</em> modules using the class be recompiled.  Make sure you delete <em>all</em> files in the <em>build output</em> (not source!) directory, re-run <code>qmake</code>, re-run the build.  It would also be interesting to test whether if you compile for release versus for debug the behaviour changes?</p>
<p dir="auto">Since you say behaviour varies according as <code>layMain</code> is first or last among the declarations, try something like:</p>
<pre><code>QVBoxLayout *dummy1, *dummy2, *dummy3, *dummy4;
QVBoxLayout *layDataPersonal, *layDataContact, *layDataLogin, *layDataBanking, *layMain;
QVBoxLayout *dummy5, *dummy6, *dummy7, *dummy8;
</code></pre>
<p dir="auto">moving the <code>*layMain</code> within its line as you please.  This gives some "dummy space" on either side of these variables in the class's layout.  Does this affect the error behaviour?</p>
<p dir="auto">Also try moving the <code>winURS</code> from the <em>stack</em> to the <em>heap</em> in your <code>main()</code>:</p>
<pre><code>    myQDialogUseraccountRegistrationSetup *winURS = new myQDialogUseraccountRegistrationSetup;
    winURS-&gt;open();
</code></pre>
]]></description><link>https://forum.qt.io/post/730632</link><guid isPermaLink="true">https://forum.qt.io/post/730632</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 29 Sep 2022 07:31:59 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Thu, 29 Sep 2022 04:03:26 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/730604">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">One thing I notice is:</p>
<p dir="auto">cbDPName = new QCheckBox("Name", tabDataPersonal);</p>
<p dir="auto">right at the start.  All the others you do not pass a QWidget as parent.  Try making this one the same, remove the , tabDataPersonal.  Any difference?</p>
</blockquote>
<p dir="auto">I removed that (did not know why I forgot it here), nothing happened.<br />
It is indeed an interesting error. I tried lots of things, even the way you mentioned with out-commenting all the widgets or not setting the layout.<br />
As I mentioned earlier, even only declaring the <code>layMain</code>inside the header causes the crash, when I declare it at the first position of all my layouts inside the class declaration. When I put it at the end of the member declarations and do not define it inside the .cpp, then it will not crash...</p>
<p dir="auto">As you say, it is a weird error and I can't believe that the code itsself is the problem. When I separate the QDialog into a separate project, it works just fine..</p>
]]></description><link>https://forum.qt.io/post/730625</link><guid isPermaLink="true">https://forum.qt.io/post/730625</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Thu, 29 Sep 2022 04:03:26 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Wed, 28 Sep 2022 20:24:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> said in <a href="/post/730589">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">From where did you know that it was line 82?</p>
</blockquote>
<p dir="auto">By looking at the screenshot you show of the <em>stack trace</em>.  In the "Zeile" column, which I suppose means "line" or "row"?  And the function name in the "Funktion" column.  And "Datei" to apparently tell you the file name.  And it's showing the "stack" or "call" trace.  You just need to look at it.</p>
<p dir="auto">It is dying during some "reparenting of child widgets", caused from the final <code>setLayout()</code> causing <code>this</code> to adopt the whole widget hierarchy.  Slightly strange error, not yet sure whether it's your code or something in Qt.</p>
<p dir="auto">One thing I notice is:</p>
<blockquote>
<p dir="auto"><code>cbDPName = new QCheckBox("Name", tabDataPersonal);</code></p>
</blockquote>
<p dir="auto">right at the start.  All the others you do <em>not</em> pass a <code>QWidget</code> as parent.  Try making this one the same, remove the <code>, tabDataPersonal</code>.  Any difference?</p>
<p dir="auto">Otherwise there are too many widgets for me to work through.  Comment out <em>all</em> those <code>new QCheckBox</code> lines and most importantly the <code>addWidget()</code>s.  Does that make it work?  Or, build <em>up</em> from <em>just</em></p>
<pre><code>        layMain = new QVBoxLayout;
        // layMain-&gt;addWidget(twMain);
        this-&gt;setLayout(layMain);  // &lt;-- line #82
</code></pre>
<p dir="auto">Nothing else.  Does that work?  Add the <code>QTabWidget</code> back in, add <em>one</em> page, ..., till it goes wrong.</p>
]]></description><link>https://forum.qt.io/post/730604</link><guid isPermaLink="true">https://forum.qt.io/post/730604</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 28 Sep 2022 20:24:16 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Wed, 28 Sep 2022 19:22:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> said in <a href="/post/730441">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">What is in line 82 in myQDialogUseraccountRegistrationSetup::myQDialogUseraccountRegistrationSetup? That's the line causing the crash according to the stack trace.</p>
</blockquote>
<p dir="auto">It is the command where I set the main layout:</p>
<pre><code>myQDialogUseraccountRegistrationSetup::myQDialogUseraccountRegistrationSetup(QWidget *parent) : QDialog(parent)
    {
        twMain = new QTabWidget;
    
        tabDataPersonal = new QWidget;
    
        cbDPName = new QCheckBox("Name", tabDataPersonal);
        cbDPPrename = new QCheckBox("Vorname");
        cbDPMiddleNames = new QCheckBox("Zwischennamen");
        cbDPDoB = new QCheckBox("Geburtsdatum");
        cbDPGender = new QCheckBox("Geschlecht");
        cbDPNationality = new QCheckBox("Nationalität");
        layDataPersonal = new QVBoxLayout;
        layDataPersonal-&gt;addWidget(cbDPName);
        layDataPersonal-&gt;addWidget(cbDPPrename);
        layDataPersonal-&gt;addWidget(cbDPMiddleNames);
        layDataPersonal-&gt;addWidget(cbDPDoB);
        layDataPersonal-&gt;addWidget(cbDPGender);
        layDataPersonal-&gt;addWidget(cbDPNationality);
        tabDataPersonal-&gt;setLayout(layDataPersonal);
        twMain-&gt;addTab(tabDataPersonal, "Persofnalien");
    
        cbDCStreet = new QCheckBox("Strasse");
        cbDCHouseNr = new QCheckBox("Hausnummer");
        cbDCZipCode = new QCheckBox("Postleitzahl");
        cbDCCity = new QCheckBox("Ort");
        cbDCRegion = new QCheckBox("Region/Kanton/Bundesland");
        cbDCState = new QCheckBox("Land");
        cbDCMail = new QCheckBox("E-Mail");
        cbDCPhoneStateCode = new QCheckBox("Ländervorwahl");
        cbDCPhonePrivate = new QCheckBox("Telefon (Privat)");
        cbDCPhoneMobile = new QCheckBox("Telefon (Mobil)");
        cbDCPhoneBusiness = new QCheckBox("Telefon (Arbeit)");
        cbDCFax = new QCheckBox("Fax");
    
        tabDataContact = new QWidget;
        layDataContact = new QVBoxLayout;
        layDataContact-&gt;addWidget(cbDCStreet);
        layDataContact-&gt;addWidget(cbDCHouseNr);
        layDataContact-&gt;addWidget(cbDCZipCode);
        layDataContact-&gt;addWidget(cbDCCity);
        layDataContact-&gt;addWidget(cbDCRegion);
        layDataContact-&gt;addWidget(cbDCState);
        layDataContact-&gt;addWidget(cbDCMail);
        layDataContact-&gt;addWidget(cbDCPhoneStateCode);
        layDataContact-&gt;addWidget(cbDCPhonePrivate);
        layDataContact-&gt;addWidget(cbDCPhoneMobile);
        layDataContact-&gt;addWidget(cbDCPhoneBusiness);
        layDataContact-&gt;addWidget(cbDCFax);
        tabDataContact-&gt;setLayout(layDataContact);
        twMain-&gt;addTab(tabDataContact, "Kontaktdaten");
    
        tabDataLogin = new QWidget;
        layDataLogin = new QVBoxLayout;
        tabDataLogin-&gt;setLayout(layDataLogin);
        twMain-&gt;addTab(tabDataLogin, "Logindaten");
    
        tabDataBanking = new QWidget;
        layDataBanking = new QVBoxLayout;
        tabDataBanking-&gt;setLayout(layDataBanking);
        twMain-&gt;addTab(tabDataBanking, "Zahlungsinformationen");
    
        layMain = new QVBoxLayout;
        layMain-&gt;addWidget(twMain);
        this-&gt;setLayout(layMain);  // &lt;-- line #82
        setWindowTitle("Registration Setup");
</code></pre>
<p dir="auto">From where did you know that it was line 82? How do I interpret the debugger text? And back to my problem: What am I doing wrong? When I use the same code in a separate project without a MainWindow, everything works just fine..</p>
]]></description><link>https://forum.qt.io/post/730589</link><guid isPermaLink="true">https://forum.qt.io/post/730589</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Wed, 28 Sep 2022 19:22:51 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Wed, 28 Sep 2022 07:27:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> said in <a href="/post/730439">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">It is shown directly in the constructor.</p>
</blockquote>
<p dir="auto">What is shown in what constructor?</p>
<p dir="auto">In any case, before going any further you need to answer <a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a>'s question.  The beauty of you having produced a stack trace is that we don't have to guess what might be wrong, we can (hopefully) determine from the trace.</p>
]]></description><link>https://forum.qt.io/post/730469</link><guid isPermaLink="true">https://forum.qt.io/post/730469</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 28 Sep 2022 07:27:12 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Wed, 28 Sep 2022 05:12:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> What is in line 82 in myQDialogUseraccountRegistrationSetup::myQDialogUseraccountRegistrationSetup? That's the line causing the crash according to the stack trace.</p>
]]></description><link>https://forum.qt.io/post/730441</link><guid isPermaLink="true">https://forum.qt.io/post/730441</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 28 Sep 2022 05:12:37 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Wed, 28 Sep 2022 04:08:25 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/730086">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">Have advised you several times already, as has <a class="plugin-mentions-user plugin-mentions-a" href="/user/mpergand">@<bdi>mpergand</bdi></a>, to compile for debug, run under debugger and look at/show us the stack view when it crashes.  Is there a particular reason you simply ignore this and continue to "guess" each time what might be wrong?  Do you not want to help yourself/us?</p>
</blockquote>
<p dir="auto">Sorry for the belated response, had no time to answer earlier.<br />
No, I'm interested in helping myself and us understanding the problem I have. I'm simply not used to the debugger, but I tried it now again:<br />
At first, a MessageBox appears in front as far as the program crashes. There it says (translated): "The process was stopped due to a signal of the operating system. Name of the signal: SIGSEGV. Meaning: Segmentation fault."<br />
Then, in the window on the bottom left, I have the following text:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/02cac021-7b79-4a4b-9215-2cd0c06ec796.png" alt="Dbg.png" class=" img-fluid img-markdown" /><br />
Well, I'm happy to hear that it was totally ok to use QDialog::exec() for my purposes. I don't know why documentation recommends to avoid that.</p>
<p dir="auto"><em>"I wonder about something else. You are using winMain as the parent of a dialog which you open(). However at that moment winMain has not actually been shown yet --- the showMaximized() only marks it for showing, the showing does not happen until the start of App.exec(). That means the dialog has a "non-shown" parent, and I wonder if that would not cause a problem."</em><br />
It is shown directly in the constructor.</p>
<p dir="auto">" <em><a class="plugin-mentions-user plugin-mentions-a" href="/user/mpergand">@<bdi>mpergand</bdi></a> suggested you might have problem because of the way you choose to use stack rather than heap variables for your windows/dialogs and their parentage, and that this may be problematic.</em>"<br />
Shouldn't I do so? You mean all my widgets inside the QDialog? In the docu, in most examples the QWidgets are created that way, aren't they?</p>
]]></description><link>https://forum.qt.io/post/730439</link><guid isPermaLink="true">https://forum.qt.io/post/730439</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Wed, 28 Sep 2022 04:08:25 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Sun, 25 Sep 2022 09:55:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a><br />
Have advised you several times already, as has <a class="plugin-mentions-user plugin-mentions-a" href="/user/mpergand">@<bdi>mpergand</bdi></a>, to compile for debug, <em>run under debugger</em> and look at/show us the <em>stack view</em> when it crashes.  Is there a particular reason you simply ignore this and continue to "guess" each time what might be wrong?  Do you not want to help yourself/us?</p>
<p dir="auto">In itself there is no problem having <code> QDialog</code> with a <code>QMainWindow</code> or setting that to its parent.  <a class="plugin-mentions-user plugin-mentions-a" href="/user/mpergand">@<bdi>mpergand</bdi></a> suggested you might have problem because of the way you choose to use <em>stack</em> rather than <em>heap</em> variables for your windows/dialogs and their parentage, and that this may be problematic.</p>
<p dir="auto">I wonder about something else.  You are using <code>winMain</code> as the parent of a dialog which you <code>open()</code>.  However at that moment <code>winMain</code> has not actually been shown yet --- the <code>showMaximized()</code> only <em>marks</em> it for showing, the showing does not happen until the start of <code>App.exec()</code>.  That means the dialog has a "non-shown" parent, and I wonder if that would not cause a problem.</p>
<p dir="auto">Ignore what the docs say about not using <code>QDialog::exec()</code>.  That is the right thing to use if you want to show a <em>modal</em> dialog, i.e. one which blocks till the user exits it.</p>
<p dir="auto">I see no point in trying to open a modal dialog with main window as parent if you are going to show it (<code>open()</code> or <code>exec()</code>) <em>prior to</em> showing the main window itself.  In particular if you want it to be modal.  I suggest you do one of the following:</p>
<ul>
<li>
<p dir="auto">Assuming you want the modal dialog to come up <em>before</em> you show the main window, use <code>winURS.exec()</code> but do <em>not</em> create via <code>winURS(&amp;winMain);</code>, just plain <code>winURS;</code>.  Does removing that parentage make it OK?</p>
</li>
<li>
<p dir="auto">If you do not want the dialog to appear till <em>after</em> the main window has been shown, and maybe use that main window for its parent, override <code>showEvent()</code> in your <code>clsWindowMain </code>, call the base implementation there first so that it gets shown, and only then create and show the dialog.</p>
</li>
</ul>
]]></description><link>https://forum.qt.io/post/730086</link><guid isPermaLink="true">https://forum.qt.io/post/730086</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 25 Sep 2022 09:55:22 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Sun, 25 Sep 2022 09:24:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mpergand">@<bdi>mpergand</bdi></a> said in <a href="/post/730035">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">You set a parent to a local instance, may lead to a double delete when winUrs runs out of scope.</p>
</blockquote>
<p dir="auto">Yes, I think that is the problem. Well, I'm asking myself about the best way to deal with a QDialog in a program where I have a QMainWindow. Should I declare the MainWindow as a parent or should I call the QDialogs independentelly?<br />
Second, I'm asking myself if it's better to call the QDialog with <code>exec()</code> or with <code>open()</code>. Documentation says I should try to avoid using <code>exec()</code>, but I see no alteranative to pause the event loop until the QDialog is finished and I need the program to pause until it is finished, I guess it is very often the purpose of QDialogs, isn't it?</p>
]]></description><link>https://forum.qt.io/post/730084</link><guid isPermaLink="true">https://forum.qt.io/post/730084</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Sun, 25 Sep 2022 09:24:37 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Sat, 24 Sep 2022 12:48:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> :</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mpergand">@<bdi>mpergand</bdi></a> said in <a href="/post/730035">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">Run your app in debug mode !</p>
</blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/730029">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">In any case, what does "the program crashes without debugging info again" mean, what did you do about running it under the debugger with:</p>
<p dir="auto">Compile for debug, let it "crash", examine the stack view window carefully to see just where it crashes and maybe why.</p>
</blockquote>
]]></description><link>https://forum.qt.io/post/730039</link><guid isPermaLink="true">https://forum.qt.io/post/730039</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 24 Sep 2022 12:48:02 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Sat, 24 Sep 2022 12:20:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> said in <a href="/post/730031">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">myQDialogUseraccountRegistrationSetup winURS(&amp;winMain);</p>
</blockquote>
<p dir="auto">You set a parent to a local instance, may lead to a double delete when winUrs runs out of scope.</p>
<p dir="auto">This line is suspicious:<br />
clsWindowMain winMain(configMain);<br />
is configMain parent of winMain ?</p>
<p dir="auto">Run your app in debug mode !</p>
]]></description><link>https://forum.qt.io/post/730035</link><guid isPermaLink="true">https://forum.qt.io/post/730035</guid><dc:creator><![CDATA[mpergand]]></dc:creator><pubDate>Sat, 24 Sep 2022 12:20:44 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Sat, 24 Sep 2022 11:50:29 GMT]]></title><description><![CDATA[<p dir="auto">Well,</p>
<p dir="auto">I realized that the problem must be the combination of my QDialog with my simultaniously showed QMainWindow.</p>
<p dir="auto">I separated the QDialog class into a new, empty project and everything works fine..</p>
<p dir="auto">I cannot post the whole project code, but maybe you see an error in my main file:</p>
<pre><code>#include &lt;QDebug&gt;
#include &lt;QApplication&gt;
#include &lt;QDir&gt;
#include &lt;QSqlDatabase&gt;
#include &lt;QSqlError&gt;
#include "clsConfigMain.h"
#include "clsWindowMain.h"
#include "myQDialogUseraccountRegistration.h"

int main(int argc, char *argv[])
{
    QApplication App(argc, argv);
    clsConfigMain configMain;
    if(configMain.criticalError())
    {
        QMessageBox::critical(nullptr, "Critical error", "A critical error occured while trying to load the main configuration. The program will exit...");
        return 1;
    }
    clsWindowMain winMain(configMain);
    winMain.showMaximized();
    myQDialogUseraccountRegistrationSetup winURS(&amp;winMain);
    winURS.open();
    int iRet = App.exec();
    qDebug() &lt;&lt; iRet;
    return iRet;
}
</code></pre>
<p dir="auto">I think the problem is that I define a QDialog object with the QMainWindow as parent. Hm..</p>
]]></description><link>https://forum.qt.io/post/730031</link><guid isPermaLink="true">https://forum.qt.io/post/730031</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Sat, 24 Sep 2022 11:50:29 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Sat, 24 Sep 2022 11:01:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> said in <a href="/post/730028">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">Ok, nope, I still have problems with it. I cannot add a fifth layout layMainto my class!</p>
</blockquote>
<p dir="auto">You seem to be saying the code you show does <em>not</em> "crash", but if you make a change it does.  Please show code which crashes, not code which works!  [Update: Yes, I may have misunderstood what you are saying here.]  (And preferably a <em>minimal example</em>, i.e. the *minimum needed to reproduce: here do you really think it is necessary to have <em>five</em> layouts with 4 tabs before there is an issue, I doubt it?)  You do not show any attempt to set <code>layMain</code> or add it in your code, as you can ascertain by searching what you have pasted, so who knows.  Maybe it's an uninitialized pointer, I don't know.  That is the case in the code you show.</p>
<p dir="auto">In any case, what does "the program crashes without debugging info again" mean, what did you do about <em>running it under the debugger</em> with:</p>
<blockquote>
<p dir="auto">Compile for debug, let it "crash", examine the <em>stack view</em> window carefully to see just where it crashes and maybe why.</p>
</blockquote>
<p dir="auto">[Because I may have misunderstood what you are saying, please start with this to discover where you say it "crashes".]</p>
<p dir="auto">On a separate matter, the code as shown does not place the <code>QTabWidget</code> on the dialog.  Why not?</p>
]]></description><link>https://forum.qt.io/post/730029</link><guid isPermaLink="true">https://forum.qt.io/post/730029</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 24 Sep 2022 11:01:37 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Sat, 24 Sep 2022 10:37:08 GMT]]></title><description><![CDATA[<p dir="auto">Ok, nope, I still have problems with it. I cannot add a fifth layout <code>layMain</code>to my class!</p>
<p dir="auto">The following works fine in the header (without initializing it):<br />
Header:</p>
<pre><code>class myQDialogUseraccountRegistrationSetup : public QDialog
{
    Q_OBJECT

private:
    QTabWidget *twMain;
    QWidget *tabDataPersonal, *tabDataContact, *tabDataLogin, *tabDataBanking;
    QVBoxLayout *layDataPersonal, *layDataContact, *layDataLogin, *layDataBanking, *layMain;

public:
    myQDialogUseraccountRegistrationSetup(QWidget *parent = nullptr);
    ~myQDialogUseraccountRegistrationSetup();
};
</code></pre>
<p dir="auto">Src:</p>
<pre><code>myQDialogUseraccountRegistrationSetup::myQDialogUseraccountRegistrationSetup(QWidget *parent) : QDialog(parent)
{
    setWindowTitle("Registration Setup");

    twMain = new QTabWidget;

    tabDataPersonal = new QWidget;
    layDataPersonal = new QVBoxLayout;
    tabDataPersonal-&gt;setLayout(layDataPersonal);
    twMain-&gt;addTab(tabDataPersonal, "Personal");

    tabDataContact = new QWidget;
    layDataContact = new QVBoxLayout;
    tabDataContact-&gt;setLayout(layDataContact);
    twMain-&gt;addTab(tabDataContact, "Contact");

    tabDataLogin = new QWidget;
    layDataLogin = new QVBoxLayout;
    tabDataLogin-&gt;setLayout(layDataLogin);
    twMain-&gt;addTab(tabDataLogin, "Login");

    tabDataBanking = new QWidget;
    layDataBanking = new QVBoxLayout;
    tabDataBanking-&gt;setLayout(layDataBanking);
    twMain-&gt;addTab(tabDataBanking, "Banking");
}
</code></pre>
<p dir="auto">Instead, when I declare <code>layMain</code>at the first position of all the layouts, the program crashes without debugging info again:</p>
<pre><code>class myQDialogUseraccountRegistrationSetup : public QDialog
{
    Q_OBJECT

private:
    QTabWidget *twMain;
    QWidget *tabDataPersonal, *tabDataContact, *tabDataLogin, *tabDataBanking;
    QVBoxLayout *layMain, *layDataPersonal, *layDataContact, *layDataLogin, *layDataBanking;

public:
    myQDialogUseraccountRegistrationSetup(QWidget *parent = nullptr);
    ~myQDialogUseraccountRegistrationSetup();
};
</code></pre>
<p dir="auto">Well, why?<br />
Second question: In case 1 where it works, it is not possible for me to initialize the <code>layMain</code>doesn't matter at which position in the constructor...</p>
<p dir="auto">Is the matter a reason of the order? I don't understand it..</p>
]]></description><link>https://forum.qt.io/post/730028</link><guid isPermaLink="true">https://forum.qt.io/post/730028</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Sat, 24 Sep 2022 10:37:08 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Sat, 24 Sep 2022 09:46:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> Alright, thank you!</p>
]]></description><link>https://forum.qt.io/post/730025</link><guid isPermaLink="true">https://forum.qt.io/post/730025</guid><dc:creator><![CDATA[Binary91]]></dc:creator><pubDate>Sat, 24 Sep 2022 09:46:54 GMT</pubDate></item><item><title><![CDATA[Reply to Crash adding QVBoxLayout to QDialog on Sat, 24 Sep 2022 09:51:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/binary91">@<bdi>Binary91</bdi></a> said in <a href="/post/730023">Crash adding QVBoxLayout to QDialog</a>:</p>
<blockquote>
<p dir="auto">I forgot to call the open() function for the myQDialog object before showing it :-)</p>
</blockquote>
<p dir="auto">I have no idea how that would cause a crash, or on the line you said it did.  For one thing, this is during the dialog <em>constructor</em>, so no "open" or "showing" can be executed till after it has finished....</p>
<p dir="auto">Yes, functions like <code>addTab()</code> or <code>setLayout()</code> deal with setting parentage for you, so you do not <em>have to</em> if you are going to use those.  It <em>can/may</em> be a little more efficient <em>not</em> to do so: creating a widget with a parent does some work on the parent (or the widget, or both, I can't remember, may apply only to adding widgets not layouts) to do with layout, then when you later e.g. set a layout on the parent and place the sub-widget on that layout it has to do new work undoing the earlier work.</p>
<p dir="auto">Having said that, I don't think it's a big deal or leads to "crashes".  I don't know whether there is an issue about setting the parent on a <code>QWidget</code> which is to go into a <code>QTabWidget</code> via <code>addTab()</code>, not sure where your crash came from, I would just follow what the docs say to do.</p>
]]></description><link>https://forum.qt.io/post/730024</link><guid isPermaLink="true">https://forum.qt.io/post/730024</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 24 Sep 2022 09:51:13 GMT</pubDate></item></channel></rss>