Files
school_archives/OSU SARL/Desktop Applications/ThreadedGuiTesting/countingthread.cpp
Corwin Perren b300c76103 Added old firmware and pcb design files
These are all design documents that I thought I had lost. It's may make
me cringe, but it's still cool to use it to see how far I've come.
2016-05-12 20:04:43 -07:00

60 lines
1000 B
C++

#include "countingthread.h"
#include <QThread>
#include <QMutex>
#include <QDebug>
CountingThread::CountingThread(QObject *parent) : QObject(parent){
Paused = false;
CurrentCount = 0;
thread = new QThread;
this->SetupCounterThread(thread);
this->moveToThread(thread);
}
void CountingThread::SetupCounterThread(QThread *cThread)
{
connect(cThread, SIGNAL(started()), this, SLOT(onStart()));
}
void CountingThread::run()
{
for(long i = 0 ; i < 10000 ; i++){
while(Paused){
thread->msleep(100);
}
CurrentCount = i;
// qDebug() << "CurrentCount = " << CurrentCount;
emit NumberChanged(i);
thread->msleep(10);
}
}
void CountingThread::SetPause()
{
Paused = true;
}
void CountingThread::ClrPause()
{
Paused = false;
}
int CountingThread::PercentComplete()
{
return CurrentCount/100;
}
void CountingThread::StartThread()
{
thread->start();
}
void CountingThread::onStart()
{
run();
}