mirror of
https://github.com/caperren/school_archives.git
synced 2025-11-09 13:41:13 +00:00
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.
60 lines
1000 B
C++
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();
|
|
}
|
|
|