Note that there are some explanatory texts on larger screens.

plurals
  1. POQObject made in QThread losing internal signal/slot connections
    primarykey
    data
    text
    <p>I have a worker <code>QThread</code> in which a <code>QObject</code> derived object is created. The object is an aggregate of two other <code>QObject</code> derived objects, as such there are internal connections for signal linking and binding the two internal objects together.</p> <p>The worker <code>QThread</code> is a member of a <code>QPlugin</code>, so is present throughout the lifetime of the plugin.</p> <p>The problem I have is that although the object is interacting fine with the rest of the application, those internal connections seem to be broken. As an experiment I tried creating the object in the main thread and the internal connections are functioning, so it is definitely something I'm doing wrong with <code>QThread</code>s.</p> <p>I also tried moving the object back to the main thread (admittedly after those internal connections are made), but it had no effect. I cycled through every type of connection (Direct, Queued, etc) for the internal connections, but it either had no effect or triggered deadlock errors. All the types passed through the connections are registered.</p> <p>The object is the parent <code>QObject</code> of the two contained objects, it shouldn't make a difference as they all reside in the same thread, but I tried setting their parent to NULL just to rule it out - it had no effect unsurprisingly. The <code>QThread</code> is <em>not</em> a parent to anything.</p> <p>The only thing I am not certain of is that the object is created from a factory singleton that resides in the main thread, but is called from the worker thread - so who does it belong to? I am at a complete loss as to what I'm doing (or not doing) to break these connections, so any help is greatly appreciated. Here is the code at the relevant parts of the application:</p> <p>This the object creation call in the worker thread, for context the object is poly mesh from an <code>OBJ</code> importer.</p> <pre><code>// Create mesh. QString type = Sy::plugMeshType + "Sy_polyMesh"; QString name = proj-&gt;newNameIncrement( "objMesh" ); Sy::PluginArgs args; args &lt;&lt; name; Sy_polyMesh* obj = Sy_pluginLoader::createInstance&lt; Sy_polyMesh &gt;( type, args ); obj-&gt;mesh() = mesh; obj-&gt;resizeBB(); result_ = obj; // If in GUI mode, register it with the project. if ( gui_ ) { proj-&gt;registerSimObject( obj ); proj-&gt;selectObject( obj ); } </code></pre> <p>I have quite an extensive plugin architecture to my app, so the actual thread starting code is abstracted into an abstract worker class:</p> <pre><code>void Sy_abstractLongProcess::begin( Sy_abstractLongProcessWorker* worker ) { worker_ = worker; worker_-&gt;moveToThread( &amp;thread_ ); QObject::connect( &amp;thread_, SIGNAL( started() ), worker_, SLOT( work() ) ); QObject* thisObj = dynamic_cast&lt; QObject* &gt;( this ); QObject::connect( &amp;thread_, SIGNAL( finished() ), worker_, SIGNAL( finished() ) ); QObject::connect( worker_, SIGNAL( finished() ), thisObj, SIGNAL( finished() ) ); QObject::connect( worker_, SIGNAL( progressChanged( double ) ), thisObj, SIGNAL( progressChanged( double ) ) ); QObject::connect( worker_, SIGNAL( finished() ), &amp;thread_, SLOT( quit() ) ); thread_.start(); } </code></pre> <p>As <em>all</em> the relevant code is spread across many classes, I won't list everything (this question is long enough), but if you need to see anything else don't hesitate to ask - I need all the help I can get on this one.</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.
    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