<?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[Design of custom dynamic interface]]></title><description><![CDATA[<p dir="auto">hello.<br />
I have a interface system that fills dinamically a container layout with a series of widgets from the pression on an entity that can be a different shape object with his class(triangle , rectangle ecc...).<br />
Each click event of each widget must be connected to a only slot runtime.<br />
Only a slot because i don't know how many widget(and relative functionality)I have because the rectangle entity for example has 3 events with relative 3 widgets with icon and text different from the  the circle entity that has 2 events(and two widget) ecc...</p>
<p dir="auto">I wish implement a connect function that create the signal / slot connection in each widget class.</p>
<p dir="auto">the problem are:</p>
<p dir="auto">1)how i can create a generic slot for connect each signal of each widget click event that manage the "sender" the widget that emit the event?</p>
<p dir="auto">i think sometings like:<br />
[code]<br />
class widgetBase: public widget<br />
{<br />
public:<br />
virtual void connect(object* pReceiver);<br />
}</p>
<p dir="auto">class customWidget : widgetBase<br />
{<br />
void connect(object* pReceiver){<br />
connect(this,SIGNAL(click()), pReceiver,SLOT(doWidgetClick(this)))</p>
<pre><code> }
</code></pre>
<p dir="auto">}</p>
<p dir="auto">class shape<br />
{<br />
public:<br />
virtual long GetWidgetCount();<br />
virtual widgetBase GetWidgetAt(int idx);<br />
virtual AddWidgetBase AddWidgetAt(widgetBase * pW);<br />
virtual RemoveWidgetBase RemoveWidgetAt(int idx);<br />
protected:<br />
Vector&lt;widgetBase*&gt;* m_pVectorWidget;</p>
<p dir="auto">}</p>
<p dir="auto">class circle : public Shape<br />
{<br />
long GetWidgetCount();<br />
widgetBase GetWidgetAt(int idx);<br />
AddWidgetBase AddWidget(widgetBase * pW); // i insert 2 widget<br />
RemoveWidgetBase RemoveWidgetAt(int idx);<br />
};<br />
class rectangle : public Shape<br />
{<br />
long GetWidgetCount();<br />
widgetBase GetWidgetAt(int idx);<br />
AddWidgetBase AddWidget(widgetBase * pW); // i insert 5 widget<br />
RemoveWidgetBase RemoveWidgetAt(int idx);<br />
};</p>
<p dir="auto">class MainDialog{</p>
<p dir="auto">void selectShape(Shape* pShape)<br />
{<br />
layout-&gt;clear();<br />
for(int i = 0; i &lt; pShape-&gt;GetWidgetCount; i++)<br />
{<br />
widgetBase* pw = pShape-&gt;m_GetWidgetAt(i);<br />
pw-&gt;connect(this);<br />
layout-&gt;addWidget(pw, this);<br />
}<br />
}<br />
slot:<br />
void doWidgetClick(customWidget * pSender)<br />
{<br />
//now i have the widget that is clicked pSender!!!!<br />
}<br />
[/code]</p>
<p dir="auto">may be is a good design?<br />
thanks for advice.<br />
by</p>
]]></description><link>https://forum.qt.io/topic/16382/design-of-custom-dynamic-interface</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 06:45:27 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/16382.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 02 May 2012 12:00:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Design of custom dynamic interface on Wed, 02 May 2012 14:37:42 GMT]]></title><description><![CDATA[<p dir="auto">I'm not quite sure about your requirements, but <em>QWidget</em> (more specifically <em>QObject</em>) has a <em>sender()</em> method, which allows for retrieving the emitting object within a slot.<br />
@<br />
void doWidgetClick()<br />
{<br />
CustomWidget <em>pSender = qobject_cast&lt;CustomWidget</em>&gt;(sender());<br />
}<br />
@<br />
For the "correct" solution design-wise you should consider using a "QSignalMapper":<a href="http://qt-project.org/doc/qt-4.8/qsignalmapper.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-4.8/qsignalmapper.html</a>.</p>
<p dir="auto">As to your code:</p>
<ul>
<li>You cannot pass values using the <em>connect()</em> statement.<br />
@<br />
// WRONG, this is a value, not a type<br />
connect(this, SIGNAL(click()), pReceiver, SLOT(doWidgetClick(this)));<br />
idget*)));<br />
@</li>
<li>Slots can only have less, not more arguments (excluding signal default arguments).<br />
@<br />
// WRONG, slot has more arguments than signal<br />
// RIGHT, only if click signal has at least one default argument<br />
connect(this, SIGNAL(click()), pReceiver, SLOT(doWidgetClick(QWidget*)));<br />
@</li>
</ul>
]]></description><link>https://forum.qt.io/post/137768</link><guid isPermaLink="true">https://forum.qt.io/post/137768</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 02 May 2012 14:37:42 GMT</pubDate></item></channel></rss>