<?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[Mine field Layout problem (solved).]]></title><description><![CDATA[<p dir="auto">Hi everyone, I've recently started  to develope a simple game (mine field) and I already have a problem.<br />
I create a QPushButton "newGame", which purpose is to create a grid of buttons.<br />
I post some lines of the code to help the explanation:</p>
<p dir="auto">@<br />
mine_field::mine_field(QWidget *parent) : QWidget(parent) {</p>
<p dir="auto">QHBoxLayout *menuLayout = new QHBoxLayout();<br />
QPushButton *newGame = new QPushButton(tr("New Game"));<br />
menuLayout-&gt;addWidget(newGame);</p>
<p dir="auto">QVBoxLayout *mainLayout = new QVBoxLayout();<br />
mainLayout-&gt;addLayout(menuLayout);<br />
setLayout(mainLayout);</p>
<p dir="auto">connect(newGame, SIGNAL(clicked()), this, SLOT(create()));<br />
}</p>
<p dir="auto">void mine_field::create()<br />
{<br />
QGridLayout *buttonLayout = new QGridLayout();<br />
for (int i=0;i&lt;10;++i)<br />
for (int j=0; j&lt;10; ++j){<br />
QPushButton *button = new QPushButton();<br />
buttonLayout-&gt;addWidget(button, i, j);<br />
}<br />
mainLayout -&gt; addLayout(buttonLayout);<br />
}<br />
@</p>
<p dir="auto">I get a segmentation fault, I think because mainLayout is not defined in function create().<br />
Anyone can help me?<br />
Thanks.</p>
]]></description><link>https://forum.qt.io/topic/35116/mine-field-layout-problem-solved</link><generator>RSS for Node</generator><lastBuildDate>Thu, 14 May 2026 12:43:03 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/35116.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Dec 2013 08:11:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Mine field Layout problem (solved). on Thu, 05 Dec 2013 17:10:13 GMT]]></title><description><![CDATA[<p dir="auto">You're welcome !</p>
<p dir="auto">Since you have it working now, please update the thread title by prepending [solved] so the other forum users may know a solution has been found :)</p>
]]></description><link>https://forum.qt.io/post/206427</link><guid isPermaLink="true">https://forum.qt.io/post/206427</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 05 Dec 2013 17:10:13 GMT</pubDate></item><item><title><![CDATA[Reply to Mine field Layout problem (solved). on Thu, 05 Dec 2013 16:10:55 GMT]]></title><description><![CDATA[<p dir="auto">Ok, I resolved the problem just declaring in constructor:<br />
@menuLayout = new QHBoxLayout ();@</p>
<p dir="auto">Thank you for your patience :)</p>
]]></description><link>https://forum.qt.io/post/206424</link><guid isPermaLink="true">https://forum.qt.io/post/206424</guid><dc:creator><![CDATA[Mangusta89]]></dc:creator><pubDate>Thu, 05 Dec 2013 16:10:55 GMT</pubDate></item><item><title><![CDATA[Reply to Mine field Layout problem (solved). on Thu, 05 Dec 2013 13:18:54 GMT]]></title><description><![CDATA[<p dir="auto">Yes, I declared it in header file:<br />
@ private:<br />
QHBoxLayout *menuLayout; @</p>
<p dir="auto">So instead of write in constructor:<br />
@ QHBoxLayout *menuLayout = new QHBoxLayout (); @</p>
<p dir="auto">Can I use it as?<br />
@ this-&gt;menuLayout @</p>
]]></description><link>https://forum.qt.io/post/206393</link><guid isPermaLink="true">https://forum.qt.io/post/206393</guid><dc:creator><![CDATA[Mangusta89]]></dc:creator><pubDate>Thu, 05 Dec 2013 13:18:54 GMT</pubDate></item><item><title><![CDATA[Reply to Mine field Layout problem (solved). on Thu, 05 Dec 2013 12:25:23 GMT]]></title><description><![CDATA[<p dir="auto">Seems you already do have it as a class member. Otherwise you wouldn't be able to compile</p>
]]></description><link>https://forum.qt.io/post/206380</link><guid isPermaLink="true">https://forum.qt.io/post/206380</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 05 Dec 2013 12:25:23 GMT</pubDate></item><item><title><![CDATA[Reply to Mine field Layout problem (solved). on Thu, 05 Dec 2013 11:19:20 GMT]]></title><description><![CDATA[<p dir="auto">Thank for the answer, how can I set mainLayout as global, visible both for constructor and for create() ?</p>
]]></description><link>https://forum.qt.io/post/206371</link><guid isPermaLink="true">https://forum.qt.io/post/206371</guid><dc:creator><![CDATA[Mangusta89]]></dc:creator><pubDate>Thu, 05 Dec 2013 11:19:20 GMT</pubDate></item><item><title><![CDATA[Reply to Mine field Layout problem (solved). on Thu, 05 Dec 2013 08:21:39 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">You are shadowing mainLayout in your constructor that's why it crashes in create()</p>
]]></description><link>https://forum.qt.io/post/206352</link><guid isPermaLink="true">https://forum.qt.io/post/206352</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 05 Dec 2013 08:21:39 GMT</pubDate></item></channel></rss>