Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you really have to pass <code>Parameter</code> by pointer to your subscribers, then you should use <code>boost::shared_ptr</code>:</p> <pre><code>typedef boost::shared_ptr&lt;Parameter&gt; SharedParameterPtr; typedef boost::signals2::signal&lt; void ( SharedParameterPtr ) &gt; signalParameterChanged_t; signalParameterChanged_t m_signalParameterChanged; // The signal source void Parameter::raiseParameterChangedSignal() { SharedParameterPtr pParameterDeepCopied = new Parameter(*this); m_signalParameterChanged(pParameterDeepCopied); } // The subscriber's handler void ClientGui::onDeviceParameterChangedHandler( SharedParameterPtr pParameter) { cout &lt;&lt; pParameter-&gt;toString() &lt;&lt; endl; } </code></pre> <p>The shared parameter object sent to your subscribers will be automatically deleted when its reference count becomes zero (i.e. it goes out of scope in all the handlers).</p> <p>Is Parameter really so heavyweight that you need to send it to your subscribers via pointer?</p> <p><strong>EDIT:</strong></p> <p>Please note that using shared_ptr takes care of lifetime management, but will not relieve you of the responsibility to make concurrent reads/writes to/from the shared parameter object thread-safe. You may well want to pass-by-copy to your subscribers for thread-safety reasons alone. In your question, it's not clear enough to me what goes on thread-wise, so I can't give you more specific recommendations.</p> <p>Is the thread calling <code>raiseParameterChangedSignal()</code> the same as your GUI thread? Some GUI toolkits don't allow concurrent use of their API by multiple threads.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload