<?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[Why do Signals have to be public?]]></title><description><![CDATA[<p dir="auto">Ever since I started using the <strong>signals-slots</strong> mechanism I found it incredibly easy to communicate between objects. However, here are a few questions that I have about this mechanism:</p>
<p dir="auto">1- Why do Signals have to be public? (Please explain the underlying mechanism)<br />
2- Do slots need to be public as well? (if yes, then why? and if not, then which is better public/private?)</p>
]]></description><link>https://forum.qt.io/topic/141875/why-do-signals-have-to-be-public</link><generator>RSS for Node</generator><lastBuildDate>Fri, 01 May 2026 14:03:21 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/141875.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 02 Jan 2023 00:55:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Why do Signals have to be public? on Mon, 02 Jan 2023 02:41:44 GMT]]></title><description><![CDATA[<p dir="auto">By emitting a signal object announces change in its state. It doesn't care if anyone is listening and it shouldn't, as it would couple it to that receiver in some way. Private signal would be a mix of concerns. The object is supposed to announce the change. It's not supposed to filter/manage who's able to get the notification. It's the job of the user to make the right connections.</p>
<p dir="auto">That's the design reason. A technical one is that in Qt4 you made connections only via <code>SIGNAL</code> macro, which just normalized signal name as a string, so signals could be private. With the function pointer based syntax you wouldn't be able to specify private <code>&amp;Class::signalName</code> in the static <code>QObject::connect</code>.</p>
<p dir="auto">Slots are a different story. In Qt5 and 6 you can make a connection to any functor, not just slots. For the purpose of connections slots are pretty much just regular member functions, so they can be public, private or protected like any other method. The only difference is they are registered as slots in meta object and can be used in the old string based connections.</p>
<p dir="auto">As to which is better - public or private. There's no better or worse. It depends on a use case. Like with regular methods you, as a designer of the class, decide what is the desired access level for given method.</p>
]]></description><link>https://forum.qt.io/post/742128</link><guid isPermaLink="true">https://forum.qt.io/post/742128</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Mon, 02 Jan 2023 02:41:44 GMT</pubDate></item><item><title><![CDATA[Reply to Why do Signals have to be public? on Mon, 02 Jan 2023 08:28:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/saviz">@<bdi>Saviz</bdi></a> said in <a href="/post/742124">Why do Signals have to be public?</a>:</p>
<blockquote>
<p dir="auto">1- Why do Signals have to be public? (Please explain the underlying mechanism)<br />
2- Do slots need to be public as well? (if yes, then why? and if not, then which is better public/private?)</p>
</blockquote>
<p dir="auto">Treat them as normal functions and you get the answer by yourself.</p>
]]></description><link>https://forum.qt.io/post/742145</link><guid isPermaLink="true">https://forum.qt.io/post/742145</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Mon, 02 Jan 2023 08:28:22 GMT</pubDate></item><item><title><![CDATA[Reply to Why do Signals have to be public? on Mon, 02 Jan 2023 02:41:44 GMT]]></title><description><![CDATA[<p dir="auto">By emitting a signal object announces change in its state. It doesn't care if anyone is listening and it shouldn't, as it would couple it to that receiver in some way. Private signal would be a mix of concerns. The object is supposed to announce the change. It's not supposed to filter/manage who's able to get the notification. It's the job of the user to make the right connections.</p>
<p dir="auto">That's the design reason. A technical one is that in Qt4 you made connections only via <code>SIGNAL</code> macro, which just normalized signal name as a string, so signals could be private. With the function pointer based syntax you wouldn't be able to specify private <code>&amp;Class::signalName</code> in the static <code>QObject::connect</code>.</p>
<p dir="auto">Slots are a different story. In Qt5 and 6 you can make a connection to any functor, not just slots. For the purpose of connections slots are pretty much just regular member functions, so they can be public, private or protected like any other method. The only difference is they are registered as slots in meta object and can be used in the old string based connections.</p>
<p dir="auto">As to which is better - public or private. There's no better or worse. It depends on a use case. Like with regular methods you, as a designer of the class, decide what is the desired access level for given method.</p>
]]></description><link>https://forum.qt.io/post/742128</link><guid isPermaLink="true">https://forum.qt.io/post/742128</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Mon, 02 Jan 2023 02:41:44 GMT</pubDate></item></channel></rss>