#include "workobject.h"
#include <QThread>

WorkObject::WorkObject(QObject *parent) : QObject(parent)
{
    _stopflag = false;
    _stoped = false;
}

WorkObject::~WorkObject()
{
    emit workclose();

    if(this->thread() != QThread::currentThread())
    {
       this->thread()->wait(20);
    }
}

void WorkObject::moveToThread(QThread *thread, bool with_thread_start)
{
    if(with_thread_start)
    {
        connect(thread, &QThread::started, this, &WorkObject::workstart);
        connect(this, &WorkObject::workclose, thread, &QThread::quit);
    }

    QObject::moveToThread(thread);
}

void WorkObject::workstart()
{
    _stoped = true;
}

