<?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] Connecting custom parent&#x27;s slot to child&#x27;s signal in constructor]]></title><description><![CDATA[<p dir="auto">EDIT: Problem was the cyclic include of header. Solved by forward-declaration.</p>
<p dir="auto">Here is the problem:</p>
<p dir="auto">I have a <em>QObject</em> based custom class which I parse as parent to another QObject based child class. I need to connect the parent's custom slot to child's custom signal in the child's constructor. The reason is that if something goes wrong on initialization of the child class it emits this signal which the parent receives and stops the app.</p>
<p dir="auto">I found out I cannot alter the constructor like this:</p>
<p dir="auto">@<br />
class child : public QObject<br />
{<br />
Q_OBJECT<br />
public:<br />
child(parentClass *parent = 0);<br />
}<br />
@</p>
<p dir="auto">as the <em>*parent</em> must be a pointer to <em>QObject</em> part of the <em>parentClass</em>. Is there any easier way I miss here other than parsing the pointer to the <em>parentClass</em> twice, once to its QObject part and once to the full object like this?</p>
<p dir="auto">@<br />
child(parentClass *p, QObject *parent = 0);<br />
@</p>
<p dir="auto">then calling</p>
<p dir="auto">@<br />
child(this,this);<br />
@</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://forum.qt.io/topic/36598/solved-connecting-custom-parent-s-slot-to-child-s-signal-in-constructor</link><generator>RSS for Node</generator><lastBuildDate>Sun, 03 May 2026 23:07:19 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/36598.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 14 Jan 2014 13:49:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] Connecting custom parent&#x27;s slot to child&#x27;s signal in constructor on Tue, 14 Jan 2014 16:25:21 GMT]]></title><description><![CDATA[<p dir="auto">ok. If you had posted this question, this would have been easier. By looking at your first question, it took the ans in different direction. Any happy ending now.</p>
]]></description><link>https://forum.qt.io/post/210772</link><guid isPermaLink="true">https://forum.qt.io/post/210772</guid><dc:creator><![CDATA[dheerendra]]></dc:creator><pubDate>Tue, 14 Jan 2014 16:25:21 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Connecting custom parent&#x27;s slot to child&#x27;s signal in constructor on Tue, 14 Jan 2014 16:18:02 GMT]]></title><description><![CDATA[<p dir="auto">Thanks, I was looking for more "elegant" solution and I found it actually. My problem was cyclic include of the parent class. The parent class was including the child's header and vice versa so it could not build. So I simply used forward declaration in the header and actual include in the implementation and now I can use the parent class pointer as parent.</p>
]]></description><link>https://forum.qt.io/post/210770</link><guid isPermaLink="true">https://forum.qt.io/post/210770</guid><dc:creator><![CDATA[Resurrection]]></dc:creator><pubDate>Tue, 14 Jan 2014 16:18:02 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Connecting custom parent&#x27;s slot to child&#x27;s signal in constructor on Tue, 14 Jan 2014 14:33:09 GMT]]></title><description><![CDATA[<p dir="auto">I don't see any issue like that. You can alter constructor.  You can pass the object twice. You can connect the signal of child to parent slot. It works perfectly. If you want the sample code give me your email id. I will send you the code right away.</p>
]]></description><link>https://forum.qt.io/post/210734</link><guid isPermaLink="true">https://forum.qt.io/post/210734</guid><dc:creator><![CDATA[dheerendra]]></dc:creator><pubDate>Tue, 14 Jan 2014 14:33:09 GMT</pubDate></item></channel></rss>