Qt GUI doesn't work with std::thread as I expect
<p>The core of my project is independent of GUI framework that's why I prefer std::thread. But Qt gives me an error when thread is using.  </p>

<blockquote>
  <p>The inferior stopped because it received a signal from the operating system.</p>
  
  <p>Signal name: SIGSEGV<br>
  Signal meaning: Segmentation fault</p>
</blockquote>

<pre><code>//MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include &lt;thread&gt;
#include &lt;mutex&gt;
#include &lt;QMainWindow&gt;

namespace Ui { class MainWindow; }

struct Observer
{
    virtual void notify() = 0;
};

class Core
{
public:
    std::thread *run()
        {
            std::thread thread(&amp;Core::runP, this);
            thread.detach();
            return &amp;thread;
        }

    void setObserver(Observer *observer) { _observer = observer; }
    int ii() const { return _ii; }
    void nextIi() { _ii++; }

    void lock()    { _mutex.lock(); }
    bool tryLock() { return _mutex.try_lock(); }
    void unlock()  { _mutex.unlock(); }

private:
    void runP()
        {
            for (int i = 1; i &lt;= 1000; i++) {
                if (i % 10 == 0) {
                    lock();
                    nextIi();
                    unlock();
                    notify();
                }
            }
        }

    void notify() { _observer-&gt;notify(); }  //!!!
    Observer *_observer;
    int _ii;
    std::mutex _mutex;
};

struct MwObserver : public Observer
{
    explicit MwObserver(struct MainWindow *mainWindow) { _mainWindow = mainWindow; }
    virtual void notify();

    MainWindow *_mainWindow;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow() { delete _ui; }
    void upd();

public slots:
    void run() { _core.run(); }

private:
    Ui::MainWindow *_ui;
    MwObserver _observer;
    Core _core;
};

inline void MwObserver::notify() { _mainWindow-&gt;upd(); }

#endif
</code></pre>

<p>-</p>

<pre><code>//MainWindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    _ui(new Ui::MainWindow),
    _observer(this)
{
    _ui-&gt;setupUi(this);
    connect(_ui-&gt;pushButtonRun, SIGNAL(clicked(bool)), this, SLOT(run()));
}

void MainWindow::upd()
{
    _core.lock();
    setWindowTitle(QString::number(_core.ii()));
    _core.unlock();
}
</code></pre>