2020년 7월 22일 수요일

간단한 Qt Thread 사용법

< MyThread.h>

class MyThread : public QThread
{
Q_OBJECT
public:
explicit MyThread(QThread *parent = 0);
virtual ~MyThread();

void startThread();
void stopThread();

protected:
virtual void run();

signals:
void started();
void finished();

protected:
bool m_bRun;
}



< MyThread.cpp>

MyThread::MyThread(QThread *parent) : QThread(parent);
{
m_bRun = false;
}

MyThread::~MyThread()
{
}

void MyThread::startThread()
{
m_bRun = true;
QThread::start();
}

void MyThread::stopThread()
{
m_bRun = false;
QThread::wait();
}

void MyThread::run()
{
emit started();

while (m_bRun)
{
...
}

emit finished();
}

댓글 없음:

댓글 쓰기