title: Create a QObject in another thread and retrieve it to the current thread = ASSERT failure in Debug on msvc16
body: <p>I am just trying to set a parent on a QObject created in another thread (the object is of course moved to the parent thread before), that's all !</p>
  <pre><code>#include &lt;QApplication&gt;
  #include &lt;QDebug&gt;
  #include &lt;QThread&gt;
  
  class Thread : public QThread //Just a convenient Class using a lambda
  {
  public:
      Thread::Thread(QObject *parent = nullptr) : QThread(parent){}
      std::function&lt;void()&gt; todo;
  protected:
      virtual void run() override{
          todo();
      }
  };
  
  int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
  
      ///////////////////////////////////////////////
      // Change this flag to switch behaviours
      bool tryToSetParentInThread = true;
      ///////////////////////////////////////////////
  
      QObject mainObj;
      QObject *dummy; //Just to get back obj created in thread;
  
      Thread thread;
      thread.todo = [&amp;](){
          //QObject *obj = new QObject(&amp;mainObj); //&quot;QObject: Cannot create children for a parent that is in a different thread.&quot; ! Of course!
  
          // So we try this
          QObject *obj = new QObject;
          dummy = obj;
  
          qDebug()&lt;&lt;obj-&gt;thread();
          obj-&gt;moveToThread(mainObj.thread());
          qDebug()&lt;&lt;obj-&gt;thread(); //Check that the Thread affinity change is done
  
          if(tryToSetParentInThread)
              obj-&gt;setParent(&amp;mainObj);
  
          QObject::connect(obj, &amp;QObject::destroyed, [](){ //Parent mecanism is OK
              qDebug()&lt;&lt;&quot;Child destroyed&quot;;
          });
      };
      thread.start();
      thread.wait();
  
      if(!tryToSetParentInThread)
          dummy-&gt;setParent(&amp;mainObj);
  
      return 0; //No need for an event loop here
  }
  </code></pre>
  <p>Edit :
  Maybe the call of <code>obj-&gt;setParent(&amp;mainObj)</code> doesn't like that mainObj is not in the thread calling the method ..?</p>
  <p>This example is working fine in release, but if you try to launch this code in debug with mscv16:</p>
  <p><a href="https://i.stack.imgur.com/jdtDI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jdtDI.png" alt="enter image description here" /></a></p>