<?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[[solved] check whether form is initialised problem]]></title><description><![CDATA[<p dir="auto">I have a fresh project with mainwindow and a second designer form class named PortSetting.<br />
I want to open the second form by clicking a pushbutton on mainwindow, but the application crashes.<br />
<em>" The program has unexpectedly finished."</em><br />
<em>part of mainwindow.cpp:</em><br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/void">@<bdi>void</bdi></a> MainWindow::on_pb_test_1_clicked()<br />
{<br />
if (!myPS) {<br />
myPS = new PortSetting(this);<br />
}</p>
<pre><code>myPS-&gt;show();
myPS-&gt;raise();
myPS-&gt;activateWindow();
</code></pre>
<p dir="auto">}@</p>
<p dir="auto">If i do not use the if-condition i can open as much forms as i want. Anyway i want to do this check,<br />
but do not know where the error is.<br />
<em>mainwindow.h:</em><br />
@#include &lt;QMainWindow&gt;<br />
#include "portsetting.h"</p>
<p dir="auto">#include &lt;QDebug&gt;</p>
<p dir="auto">namespace Ui {<br />
class MainWindow;<br />
}</p>
<p dir="auto">class MainWindow : public QMainWindow<br />
{<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
explicit MainWindow(QWidget *parent = 0);<br />
~MainWindow();</p>
<p dir="auto">private slots:<br />
void on_pb_test_1_clicked();</p>
<p dir="auto">private:<br />
Ui::MainWindow *ui;<br />
PortSetting *myPS;</p>
<p dir="auto">};@</p>
<p dir="auto"><em>portsetting.h :</em><br />
@#include &lt;QMainWindow&gt;<br />
#include &lt;QDialog&gt;</p>
<p dir="auto">namespace Ui {<br />
class PortSetting;<br />
}</p>
<p dir="auto">class PortSetting : public QDialog<br />
{<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
explicit PortSetting(QWidget *parent = 0);<br />
~PortSetting();</p>
<p dir="auto">private:<br />
Ui::PortSetting *ui;</p>
<p dir="auto">};<br />
@</p>
<p dir="auto"><em>portsetting.cpp:</em><br />
@#include "portsetting.h"<br />
#include "ui_portsetting.h"</p>
<p dir="auto">PortSetting::PortSetting(QWidget *parent) :<br />
QDialog(parent),<br />
ui(new Ui::PortSetting)<br />
{<br />
ui-&gt;setupUi(this);<br />
}</p>
<p dir="auto">PortSetting::~PortSetting()<br />
{<br />
delete ui;<br />
}@</p>
<p dir="auto">there is portsetting.ui but i think its not necessary to post here.<br />
The form contains a single pushbutton connected to PortSetting  close()</p>
]]></description><link>https://forum.qt.io/topic/39367/solved-check-whether-form-is-initialised-problem</link><generator>RSS for Node</generator><lastBuildDate>Mon, 15 Jun 2026 18:10:24 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/39367.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 23 Mar 2014 08:25:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [solved] check whether form is initialised problem on Mon, 24 Mar 2014 09:08:59 GMT]]></title><description><![CDATA[<p dir="auto">It only works on QObjects but besides that, I'd say no reason not to. Unless someone here wants to correct me.</p>
]]></description><link>https://forum.qt.io/post/219764</link><guid isPermaLink="true">https://forum.qt.io/post/219764</guid><dc:creator><![CDATA[frankiefrank]]></dc:creator><pubDate>Mon, 24 Mar 2014 09:08:59 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] check whether form is initialised problem on Mon, 24 Mar 2014 09:06:26 GMT]]></title><description><![CDATA[<p dir="auto">Isn't it a good idea to do so always ?</p>
]]></description><link>https://forum.qt.io/post/219762</link><guid isPermaLink="true">https://forum.qt.io/post/219762</guid><dc:creator><![CDATA[deleted28]]></dc:creator><pubDate>Mon, 24 Mar 2014 09:06:26 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] check whether form is initialised problem on Mon, 24 Mar 2014 09:03:22 GMT]]></title><description><![CDATA[<p dir="auto">There's nothing to show really - you just declare your member as</p>
<p dir="auto">@QPointer&lt;PortSetting&gt;@</p>
<p dir="auto">And it behaves like PortSetting* but with a few benefits, including it being initialized with 0 without you explicitly writing it.</p>
<p dir="auto">See <a href="http://qt-project.org/doc/qt-5/QPointer.html#details" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5/QPointer.html#details</a></p>
]]></description><link>https://forum.qt.io/post/219761</link><guid isPermaLink="true">https://forum.qt.io/post/219761</guid><dc:creator><![CDATA[frankiefrank]]></dc:creator><pubDate>Mon, 24 Mar 2014 09:03:22 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] check whether form is initialised problem on Mon, 24 Mar 2014 08:57:13 GMT]]></title><description><![CDATA[<p dir="auto">bq. It would be cleaner to use QPointer&lt;T&gt; for your data member.</p>
<p dir="auto">May you be so kind and show me a minimal example of this approach, please.</p>
]]></description><link>https://forum.qt.io/post/219757</link><guid isPermaLink="true">https://forum.qt.io/post/219757</guid><dc:creator><![CDATA[deleted28]]></dc:creator><pubDate>Mon, 24 Mar 2014 08:57:13 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] check whether form is initialised problem on Sun, 23 Mar 2014 17:26:45 GMT]]></title><description><![CDATA[<p dir="auto">To expand on Arnaut comment - your PortSetting* pointer would have a dirty but non-null value. That's why the if clause would not be entered (since it's not null) and you would try to call the show() on some random memory spot.</p>
<p dir="auto">It would be cleaner to use QPointer&lt;T&gt; for your data member.</p>
<p dir="auto">Edit: Whoops! I need to get used to refreshing my windows more often!</p>
]]></description><link>https://forum.qt.io/post/219664</link><guid isPermaLink="true">https://forum.qt.io/post/219664</guid><dc:creator><![CDATA[frankiefrank]]></dc:creator><pubDate>Sun, 23 Mar 2014 17:26:45 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] check whether form is initialised problem on Sun, 23 Mar 2014 16:42:19 GMT]]></title><description><![CDATA[<p dir="auto">works!, thank you very much.<br />
I think i have to repeat some lectures :)</p>
]]></description><link>https://forum.qt.io/post/219660</link><guid isPermaLink="true">https://forum.qt.io/post/219660</guid><dc:creator><![CDATA[deleted28]]></dc:creator><pubDate>Sun, 23 Mar 2014 16:42:19 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] check whether form is initialised problem on Sun, 23 Mar 2014 16:32:25 GMT]]></title><description><![CDATA[<p dir="auto">bq. line4 : isn’t initilisation ?</p>
<p dir="auto">but you use (check) the pointer before (line 3 ).</p>
<p dir="auto">Add<br />
@myPs = NULL@</p>
<p dir="auto">to your main window constructor.</p>
<p dir="auto">Regards,<br />
H.</p>
]]></description><link>https://forum.qt.io/post/219659</link><guid isPermaLink="true">https://forum.qt.io/post/219659</guid><dc:creator><![CDATA[Arnaut]]></dc:creator><pubDate>Sun, 23 Mar 2014 16:32:25 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] check whether form is initialised problem on Sun, 23 Mar 2014 16:19:56 GMT]]></title><description><![CDATA[<p dir="auto">line4 : isn't initilisation ?</p>
<p dir="auto">part of mainwindow.cpp:</p>
<p dir="auto">1    void MainWindow::on_pb_test_1_clicked()<br />
2    {<br />
3        if (!myPS) {<br />
4            myPS = new PortSetting(this);<br />
}</p>
<p dir="auto">and private declaration in mainwindow.h ?</p>
<p dir="auto">Do you have a suggestion ?</p>
]]></description><link>https://forum.qt.io/post/219654</link><guid isPermaLink="true">https://forum.qt.io/post/219654</guid><dc:creator><![CDATA[deleted28]]></dc:creator><pubDate>Sun, 23 Mar 2014 16:19:56 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] check whether form is initialised problem on Sun, 23 Mar 2014 15:33:04 GMT]]></title><description><![CDATA[<p dir="auto">Do you initialize the <em>myPS</em> pointer somewhere ?</p>
<p dir="auto">Regards,<br />
H.</p>
]]></description><link>https://forum.qt.io/post/219648</link><guid isPermaLink="true">https://forum.qt.io/post/219648</guid><dc:creator><![CDATA[Arnaut]]></dc:creator><pubDate>Sun, 23 Mar 2014 15:33:04 GMT</pubDate></item></channel></rss>