Note that there are some explanatory texts on larger screens.

plurals
  1. POqt signals/slots in a plugin
    primarykey
    data
    text
    <p>I have an app with such structure: all the datatypes (<code>class INode</code>) are stored in plugins (DLLs). Some of the datatypes can be drawn (if they're <code>IDrawable</code>). </p> <p>To load an object of, e.g. <code>class PointCloudNode: public INode</code> I have a special input plugin (DLL) which is called <code>class PointCloudParser: public IIOPlugin</code> and <code>IIOPlugin</code> is a thread with some specific functionality: <code>class IIOPlugin: public QThread</code>.</p> <p>All the objects are created by <code>NodeFactory</code> class which is a singleton stored in separate DLL.</p> <p>And here's the problem:</p> <pre><code>void PointCloudNode::update() { QObject::connect (this,SIGNAL(tmptmp()),this,SLOT(drawObject())); emit tmptmp(); } </code></pre> <p>If I do this from any thread (main thread or the Input Plugin thread)</p> <pre><code>NodeFactory* fab = NodeFactory::getInstance(); boost::shared_ptr&lt;INode&gt; pc(fab-&gt;createNode("pointCloud","myPC")); boost::shared_ptr&lt;IDrawable&gt; dr = boost::dynamic_pointer_cast&lt;IDrawable&gt;(pc); dr-&gt;update(); </code></pre> <p>The update launches, the <code>tmptmp()</code> signal is emitted, and the slot (<code>drawObject()</code>) executes correctly.</p> <p><b>BUT</b> if do just the same, but create the object in my Input Plugin, pass over the shared pointer and execute <code>dr->update()</code> in another function, the slot <code>drawObject()</code> is never entered though all the code is executed (including <code>connect</code>, etc.).</p> <p>To be more precise, here's the Input Plugin:</p> <pre><code> void PointCloudParserPlugin::doLoad(const QString&amp; inputName, boost::shared_ptr&lt;INode&gt; container) { NodeFactory* factory = NodeFactory::getInstance(); boost::shared_ptr&lt;INode&gt; node = factory-&gt;createNode("pointCloud", inputName); // here goes the loading itself, nothing special... container-&gt;addChild(node); //that's the container where I keep all the objects //boost::dynamic_pointer_cast&lt;IDrawable&gt;(container-&gt;getChild(inputName))-&gt;update(); //If I uncomment this line, it all works: the slot is launched. emit loadingFinished(inputName); // it executes the following function } </code></pre> <p>The last emit is connected to this:</p> <pre><code> void GeomBox::updateVisualization(const QString&amp; fileName) { boost::shared_ptr&lt;INode&gt; node = container_-&gt;getChild(fileName); boost::shared_ptr&lt;IDrawable&gt; nodeDrawable = boost::dynamic_pointer_cast&lt;IDrawable&gt;(node); nodeDrawable-&gt;update(); //this is the problem line: update() executes, connect() works, but the slot never runs :( } </code></pre> <p>How come? The <code>node</code> object is the same all the way through, it is valid. Every line in code in launched, <code>QObject::connect</code> doesn't write anything to debug window, the signal <code>tmptmp()</code> is emitted, but the slot <code>drawObject()</code> in one case is never reached? Any ideas?</p> <p><b>Upd.:</b> If I do not inherit <code>IIOPlugin</code> from <code>QThread</code>, everything works fine (i.e. load the object in the main thread). I expected the signals/slots to work across the threads...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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