添加多线程触发相机
parent
322864e26e
commit
7bf6482e6a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,43 @@
|
|||||||
|
#include "CThread.h"
|
||||||
|
|
||||||
|
CThread::CThread(QObject *parent)
|
||||||
|
: QThread(parent)
|
||||||
|
{
|
||||||
|
m_abort = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
CThread::~CThread()
|
||||||
|
{
|
||||||
|
mutex.lock();
|
||||||
|
m_abort = true;
|
||||||
|
mutex.unlock();
|
||||||
|
|
||||||
|
wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CThread::startProcess()
|
||||||
|
{
|
||||||
|
m_abort = false;
|
||||||
|
start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CThread::stopProcess()
|
||||||
|
{
|
||||||
|
mutex.lock();
|
||||||
|
m_abort = true;
|
||||||
|
mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CThread::run()
|
||||||
|
{
|
||||||
|
while (1) {
|
||||||
|
if (m_func)
|
||||||
|
{
|
||||||
|
m_func();
|
||||||
|
}
|
||||||
|
if(m_abort)
|
||||||
|
break;
|
||||||
|
int ms = m_sleepms > 1 ? m_sleepms : 1;
|
||||||
|
msleep(ms);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
#ifndef _CTHREAD_H_
|
||||||
|
#define _CTHREAD_H_
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
#include <QMutex>
|
||||||
|
#include <functional>
|
||||||
|
typedef std::function<void(void)> TaskFunc;
|
||||||
|
class CThread : public QThread
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
CThread(QObject *parent = 0);
|
||||||
|
~CThread();
|
||||||
|
void startProcess();
|
||||||
|
void setTaskFunc(TaskFunc func) {
|
||||||
|
m_func = func;
|
||||||
|
}
|
||||||
|
void setSleepms(int m_time = 1)
|
||||||
|
{
|
||||||
|
m_sleepms = m_time;
|
||||||
|
}
|
||||||
|
public slots:
|
||||||
|
void stopProcess();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void run();
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_abort;
|
||||||
|
QMutex mutex;
|
||||||
|
int m_sleepms{ 10 };
|
||||||
|
TaskFunc m_func;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ! _CTHREAD_H_
|
||||||
Loading…
Reference in New Issue