<?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[How do I attach the private data come along with signal() and send it to the slot()?]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I would like to get the caller's object private data, who call the slot.  Any suggestions, please.</p>
<p dir="auto">The Scenario:<br />
The Package Class Handler -&gt; many classes was called ... -&gt; The Slot Class.</p>
<p dir="auto">The Package Class Handler has to be attached the private data to some object.</p>
<pre><code>void PackgeHandler::unpack(void)
{
...
    // Somehow to attach the private data to "e" and emit the signal to the slot.
    // How to attach the private data to the object?  Please.
    emit mousePressEvent(e);
...
}
</code></pre>
<p dir="auto">The Slot Class will take it and see the information.</p>
<pre><code>// I have compiled the container_of() and no error reported.
template&lt;class P, class M&gt;
size_t cpp_offsetof(const M P::*member)
{
    return (size_t) &amp;( reinterpret_cast&lt;P*&gt;(0)-&gt;*member);
}

template&lt;class P, class M&gt;
P* container_of(M* ptr, const M P::*member)
{
    return (P*)( (char*)ptr - cpp_offsetof(member));
}

void Button::mousePressEvent(QMouseEvent *e)
{
    // What is A &amp; B?
    // Assume the attached private data is represented to QObject or other class-type.
    QObject myObj = container_of(A, B;
    ...
}
</code></pre>
<p dir="auto">The PackgeHandler and Button Classes in living on different DLL file, both of them are plug-in.<br />
Can not create new signal / slot, because the architecture has to be no changes.</p>
<p dir="auto">Question:<br />
I do not know, how to use container_of()?  Does it work in this way?<br />
Or could you suggest me with any method would work for me?</p>
<p dir="auto">Thank you so much,<br />
Abhisit.</p>
]]></description><link>https://forum.qt.io/topic/98920/how-do-i-attach-the-private-data-come-along-with-signal-and-send-it-to-the-slot</link><generator>RSS for Node</generator><lastBuildDate>Fri, 24 Apr 2026 13:34:44 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/98920.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 25 Jan 2019 06:24:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How do I attach the private data come along with signal() and send it to the slot()? on Fri, 25 Jan 2019 10:02:12 GMT]]></title><description><![CDATA[<h3>This is a hack to fit the question requirements. It's not the best solution</h3>
<p dir="auto">Assuming that in <code>emit mousePressEvent(e);</code>, <code>e</code> is of type <code>QMouseEvent *</code> you could subclass</p>
<pre><code class="language-cpp">class DataMouseEvent : public QMouseEvent {
public:
using QMouseEvent::QMouseEvent;
QVariant member;
};
</code></pre>
<p dir="auto">and change <code>e</code> to be type <code>DataMouseEvent</code>. Then in <code>Button::mousePressEvent(QMouseEvent *e)</code> you can just <code>dynamic_cast&lt;DataMouseEvent*&gt;(e)-&gt;member;</code></p>
]]></description><link>https://forum.qt.io/post/507101</link><guid isPermaLink="true">https://forum.qt.io/post/507101</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Fri, 25 Jan 2019 10:02:12 GMT</pubDate></item><item><title><![CDATA[Reply to How do I attach the private data come along with signal() and send it to the slot()? on Fri, 25 Jan 2019 08:29:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/abhisit">@<bdi>abhisit</bdi></a> said in <a href="/post/507052">How do I attach the private data come along with signal() and send it to the slot()?</a>:</p>
<blockquote>
<p dir="auto">Because the architecture has to be no changes</p>
</blockquote>
<p dir="auto">?<br />
How do you want to pass private data without changing the interface?!</p>
]]></description><link>https://forum.qt.io/post/507082</link><guid isPermaLink="true">https://forum.qt.io/post/507082</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Fri, 25 Jan 2019 08:29:10 GMT</pubDate></item><item><title><![CDATA[Reply to How do I attach the private data come along with signal() and send it to the slot()? on Fri, 25 Jan 2019 06:39:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/aha_1980">@<bdi>aha_1980</bdi></a> Thanks,  I can not create the new signal / slot. Because the architecture has to be no changes.</p>
]]></description><link>https://forum.qt.io/post/507052</link><guid isPermaLink="true">https://forum.qt.io/post/507052</guid><dc:creator><![CDATA[abhisit]]></dc:creator><pubDate>Fri, 25 Jan 2019 06:39:11 GMT</pubDate></item><item><title><![CDATA[Reply to How do I attach the private data come along with signal() and send it to the slot()? on Fri, 25 Jan 2019 06:27:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/abhisit">@<bdi>abhisit</bdi></a> simply create a new signal that takes all your data and emit that.</p>
]]></description><link>https://forum.qt.io/post/507049</link><guid isPermaLink="true">https://forum.qt.io/post/507049</guid><dc:creator><![CDATA[aha_1980]]></dc:creator><pubDate>Fri, 25 Jan 2019 06:27:39 GMT</pubDate></item></channel></rss>