<?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[Map signal to slots in vector of widgets]]></title><description><![CDATA[<p dir="auto">Say I a widget A and a vector of widget B's (the number of which is only known at runtime and is dynamic)</p>
<p dir="auto">I would like a signal / slot relationship between A and all B's, such that I can choose the slot of which of the widget B's recieves the signal.</p>
<p dir="auto">i.e some sort of emit widgetASignal (slotOfWidgetB_X, double amount)</p>
<p dir="auto">Now, I am aware of QSignalMapper, but as far as I can tell that is for the counterpart of what I would like i.e QSignalMaper would be vector of widget B's, one of which sends a signal, and widget A slot recieves the signal and can work out which of widget B's it came from.</p>
<p dir="auto">I want  to do the opposite here, and emit a signal defined in widgetA and it get to only one of the instances of widgetB.</p>
<p dir="auto">Any help much appreciated.</p>
]]></description><link>https://forum.qt.io/topic/54651/map-signal-to-slots-in-vector-of-widgets</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 15:47:18 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/54651.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 27 May 2015 12:33:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Map signal to slots in vector of widgets on Sun, 31 May 2015 22:01:55 GMT]]></title><description><![CDATA[<p dir="auto">I think there's a deeper problem here. Conceptual one.<br />
The object emitting a signal is not suppose to know anything about the receivers. It's only role is to signal something. Who and how reacts to it should not be of its concern.<br />
So conceptually at least it's not a case where you would use a signal/slot mechanism. In your case object A is perfectly aware of the existence and placement of objects B, so it might just as well call their method directly.</p>
<p dir="auto">If you insist on using a signal/slot here I would create a manager object for the vector, emit something like <code>signalFromA(int index, double amount)</code> and in the slot of the manager simply do something like <code>slotOfManager(int index, double amount) { vectorOfBs[index]-&gt;doStuff(amount);  }</code>, but again, that really doesn't look like a job for signals/slots. You might as well hold a pointer (or a ref) to the vector in the A and call <code>doStuff</code> of wanted B directly.</p>
]]></description><link>https://forum.qt.io/post/276155</link><guid isPermaLink="true">https://forum.qt.io/post/276155</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Sun, 31 May 2015 22:01:55 GMT</pubDate></item><item><title><![CDATA[Reply to Map signal to slots in vector of widgets on Sun, 31 May 2015 20:53:27 GMT]]></title><description><![CDATA[<p dir="auto">Don't use static_cast with QObject derived classes, there's qobject_cast for that</p>
]]></description><link>https://forum.qt.io/post/276145</link><guid isPermaLink="true">https://forum.qt.io/post/276145</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sun, 31 May 2015 20:53:27 GMT</pubDate></item><item><title><![CDATA[Reply to Map signal to slots in vector of widgets on Sun, 31 May 2015 09:57:10 GMT]]></title><description><![CDATA[<p dir="auto">Maybe connect signals from all objects to same slot and in slot do something like this:</p>
<pre><code>TargetClass* target1 = new TargetClass();
TargetClass* target2 = new TargetClass();

connect (target1, SIGNAL( doSomething()), this, SLOT( onDoSomething()));
connect (target2, SIGNAL( doSomething()), this, SLOT( onDoSomething()));
</code></pre>
<p dir="auto">inside onDoSomething</p>
<pre><code>TargetClass *targe = static_cast&lt;TargetClass*&gt;( this-&gt;sender());
target-&gt;doSomething();
</code></pre>
<p dir="auto">Also if You are working with Ui classes (widgets) then parent-&gt;findChildrens will come in handy (i.e. to get all widgets for the parent and i.e. uncheck all checkboxes except for the current one - although this con be done purely using proper widgets).</p>
]]></description><link>https://forum.qt.io/post/276119</link><guid isPermaLink="true">https://forum.qt.io/post/276119</guid><dc:creator><![CDATA[LuGRU]]></dc:creator><pubDate>Sun, 31 May 2015 09:57:10 GMT</pubDate></item><item><title><![CDATA[Reply to Map signal to slots in vector of widgets on Sat, 30 May 2015 21:46:04 GMT]]></title><description><![CDATA[<p dir="auto">I've rephrased my original not very readable question.</p>
]]></description><link>https://forum.qt.io/post/276092</link><guid isPermaLink="true">https://forum.qt.io/post/276092</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 30 May 2015 21:46:04 GMT</pubDate></item><item><title><![CDATA[Reply to Map signal to slots in vector of widgets on Sat, 30 May 2015 21:43:59 GMT]]></title><description><![CDATA[<p dir="auto">Yes, I want to decide which widget receives the signal.</p>
]]></description><link>https://forum.qt.io/post/276091</link><guid isPermaLink="true">https://forum.qt.io/post/276091</guid><dc:creator><![CDATA[oracle3001]]></dc:creator><pubDate>Sat, 30 May 2015 21:43:59 GMT</pubDate></item><item><title><![CDATA[Reply to Map signal to slots in vector of widgets on Sat, 30 May 2015 21:45:24 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">How do you decide which widget should receive the signal ?</p>
<p dir="auto">[edit: corrected unclear question… SGaist]</p>
]]></description><link>https://forum.qt.io/post/275895</link><guid isPermaLink="true">https://forum.qt.io/post/275895</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 30 May 2015 21:45:24 GMT</pubDate></item></channel></rss>