<?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[Where should I connect signals with slots]]></title><description><![CDATA[<p dir="auto">Currently, I have about 10 classes in my project. I had included all other class headers to my mainwidget.h. Created objects and instantiated them in header. And in my mainwidget.cpp i am using <code>connect()</code>  keywords for all signals and slots in project. Normally how should i do this?</p>
<p dir="auto">For example now I have <code>ClassX</code>, it emits <code>startSignal</code> and <code>ClassY</code>'s <code>startSlot</code> will be responsible with that signal, and after doing its job it need to disconnect the signal. Maybe I can pass ClassX object to ClassY when creating objects in mainwidget, and connect them in ClassY. I am not sure that should be done in this way.</p>
<p dir="auto">Shortly, I am demanding for advices, how to/where to connect signals and slots properly.</p>
]]></description><link>https://forum.qt.io/topic/142451/where-should-i-connect-signals-with-slots</link><generator>RSS for Node</generator><lastBuildDate>Wed, 13 May 2026 01:24:00 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/142451.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 Jan 2023 05:42:10 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Where should I connect signals with slots on Thu, 26 Jan 2023 12:30:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> X emits the another signal but nevermind, I changed the codes so not need for passing them each other now.</p>
]]></description><link>https://forum.qt.io/post/745262</link><guid isPermaLink="true">https://forum.qt.io/post/745262</guid><dc:creator><![CDATA[masa4]]></dc:creator><pubDate>Thu, 26 Jan 2023 12:30:45 GMT</pubDate></item><item><title><![CDATA[Reply to Where should I connect signals with slots on Thu, 26 Jan 2023 12:20:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/masa4">@<bdi>masa4</bdi></a> said in <a href="/post/745256">Where should I connect signals with slots</a>:</p>
<blockquote>
<p dir="auto">And I want the y  object in X class because I will send another signal if Y is visible</p>
</blockquote>
<p dir="auto">Who will emit this other signal? X or Y?<br />
In general you should avoid such circular dependencies - this is bad design.</p>
]]></description><link>https://forum.qt.io/post/745261</link><guid isPermaLink="true">https://forum.qt.io/post/745261</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 26 Jan 2023 12:20:44 GMT</pubDate></item><item><title><![CDATA[Reply to Where should I connect signals with slots on Thu, 26 Jan 2023 11:30:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/masa4">@<bdi>masa4</bdi></a><br />
It is unlikely each object should want a reference to the other object, that tends to lead to mutual recursion.</p>
<p dir="auto">Slots should be connected to signals from somewhere which can "see" both the signal and the slot.  This might be in the slot class, or it might be in another class which includes both signal &amp; slot classes.  What you should <em>not</em> do is connect to an external slot class from the signal class --- slots may know about signals, but signals should never know about slots.</p>
]]></description><link>https://forum.qt.io/post/745257</link><guid isPermaLink="true">https://forum.qt.io/post/745257</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 26 Jan 2023 11:30:00 GMT</pubDate></item><item><title><![CDATA[Reply to Where should I connect signals with slots on Thu, 26 Jan 2023 10:49:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> I want to emit a signal from X class for a slot in Y class. Y will disconnect after its process done. And I want the y  object in X class because I will send another signal if Y is visible. In this situation i thought i need each object in each class.</p>
]]></description><link>https://forum.qt.io/post/745256</link><guid isPermaLink="true">https://forum.qt.io/post/745256</guid><dc:creator><![CDATA[masa4]]></dc:creator><pubDate>Thu, 26 Jan 2023 10:49:11 GMT</pubDate></item><item><title><![CDATA[Reply to Where should I connect signals with slots on Thu, 26 Jan 2023 10:45:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chrisw67">@<bdi>ChrisW67</bdi></a> So I cant pass them each other?</p>
]]></description><link>https://forum.qt.io/post/745255</link><guid isPermaLink="true">https://forum.qt.io/post/745255</guid><dc:creator><![CDATA[masa4]]></dc:creator><pubDate>Thu, 26 Jan 2023 10:45:01 GMT</pubDate></item><item><title><![CDATA[Reply to Where should I connect signals with slots on Thu, 26 Jan 2023 07:55:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/chrisw67">@<bdi>ChrisW67</bdi></a> Oh, yes!<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/masa4">@<bdi>masa4</bdi></a> Why would you need to pass y pointer to x?</p>
<pre><code>x = new ClassX();
y = new ClassY(x);
</code></pre>
]]></description><link>https://forum.qt.io/post/745244</link><guid isPermaLink="true">https://forum.qt.io/post/745244</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 26 Jan 2023 07:55:36 GMT</pubDate></item><item><title><![CDATA[Reply to Where should I connect signals with slots on Thu, 26 Jan 2023 07:39:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/masa4">@<bdi>masa4</bdi></a> said in <a href="/post/745239">Where should I connect signals with slots</a>:</p>
<blockquote>
<pre><code>x = new ClassX(y);
y = new ClassY(x);
</code></pre>
</blockquote>
<p dir="auto">In the first line the value of <code>y</code> is undefined</p>
]]></description><link>https://forum.qt.io/post/745242</link><guid isPermaLink="true">https://forum.qt.io/post/745242</guid><dc:creator><![CDATA[ChrisW67]]></dc:creator><pubDate>Thu, 26 Jan 2023 07:39:13 GMT</pubDate></item><item><title><![CDATA[Reply to Where should I connect signals with slots on Thu, 26 Jan 2023 06:30:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/masa4">@<bdi>masa4</bdi></a> Yes, this is good.<br />
If you're using pointers you do not even need to include ClassX/ClassY header files in mainwindow.h. Instead use forward declaration and include the header files in mainwindow.cpp:</p>
<pre><code>// In mainwindow.h
class ClassX; // Forward declaration for ClassX
class ClassY; // Forward declaration for ClassY

ClassX *x;
ClassY *y;

// In mainwindow.cc
#include "classx_header_file.h"
#include "classy_header_file.h"

x = new ClassX(y);
y = new ClassY(x);
</code></pre>
<p dir="auto">This technique makes header files smaller and helps to reduce compile time.</p>
]]></description><link>https://forum.qt.io/post/745240</link><guid isPermaLink="true">https://forum.qt.io/post/745240</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 26 Jan 2023 06:30:04 GMT</pubDate></item><item><title><![CDATA[Reply to Where should I connect signals with slots on Thu, 26 Jan 2023 06:25:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> Thanks for answer. As an additional question, is it ok too?<br />
mainwidget.h:</p>
<pre><code>ClassX *x;
ClassY *y;
</code></pre>
<p dir="auto">mainwidget.cpp(constructor):</p>
<pre><code>x = new ClassX(y);
y = new ClassY(x);
</code></pre>
<p dir="auto">And yes I need to move instantiation to .cpp.</p>
]]></description><link>https://forum.qt.io/post/745239</link><guid isPermaLink="true">https://forum.qt.io/post/745239</guid><dc:creator><![CDATA[masa4]]></dc:creator><pubDate>Thu, 26 Jan 2023 06:25:28 GMT</pubDate></item><item><title><![CDATA[Reply to Where should I connect signals with slots on Thu, 26 Jan 2023 06:19:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/masa4">@<bdi>masa4</bdi></a> said in <a href="/post/745237">Where should I connect signals with slots</a>:</p>
<blockquote>
<p dir="auto">Created objects and instantiated them in header</p>
</blockquote>
<p dir="auto">In header?! This is usually done in cpp, not in header files.<br />
If ClassY needs to disconnect from the signale then yes you can pass pointer to ClassX to ClassY, so ClassY can connect and later disconnect from the ClassX signal.<br />
If there is no need to disconnect from signal then you can simply call connect where you're creating ClassX and ClassY instances.</p>
]]></description><link>https://forum.qt.io/post/745238</link><guid isPermaLink="true">https://forum.qt.io/post/745238</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 26 Jan 2023 06:19:51 GMT</pubDate></item></channel></rss>