title: Call Qt object method from another std::thread
body: <p>I have simple Qt form which represents main window of my app. It has method:</p>
  
  <pre><code>void gui_popup::on_pushButton_clicked()
  {
      QString text = ui-&gt;MainText-&gt;toPlainText();
      text = "1\n" + text;
      ui-&gt;MainText-&gt;setText(text);
  }
  </code></pre>
  
  <p>Also I have some code, running in another thread, created like this:</p>
  
  <pre><code>std:thread* core_thread = new thread(&amp;Init); //void Init()...
  </code></pre>
  
  <p>Then, at some moment or condition code from <em>std::thread</em> need to call <em>gui_popup::on_pushButton_clicked()</em>. I'm trying to do it like this:</p>
  
  <pre><code>void test_callback(void* object_ptr)
  {
      auto this_object = (gui_popup*)object_ptr;
      this_object-&gt;on_pushButton_clicked();
  }
  </code></pre>
  
  <p>In std::thread code I'm saving <em>test_callback</em> pointer and <em>gui_popup</em> object pointer. But when it starts calling <em>on_pushButton_clicked()</em> program halts with segmentation fault error. This code works fine with some other simple classes, but not with QtObject. What am I doing wrong?</p>
  
  <p><strong>UPDATE:</strong>
  I've solved it this way:</p>
  
  <pre><code>void test_callback(void* object_ptr)
  {
      QMetaObject qtmo;
      qtmo.invokeMethod((gui_popup*)object_ptr, "on_pushButton_clicked");
  }
  </code></pre>
  
  <p>it is, of course, much more complex than using QThread, emitting signals and all other suggested solutions. However thank you everyone for trying to help.</p>