FlashWizard
::FlashWizard(QWidget *parent
) : QWizard
(parent
), ui
(new Ui
::FlashWizard){
ui->setupUi(this);
ui->pbReading->reset();
ui->pbWriting->reset();
ui->lblReadingStatus->setText("");
ui->lblReadingStatus->setText("");
ui->lblProgStatus->setText("");
connect(ui->introPage, SIGNAL(p1_updateLabelOne(const QString&)), this, SLOT(updateLabel(const QString&)));
connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(pageCleanUp(int)));
worker = new Worker;
worker->moveToThread(workerThread);
connect(workerThread, SIGNAL(started()), worker, SLOT(start()));
connect(worker, SIGNAL(finished()), workerThread, SLOT(quit()));
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater()));
connect(workerThread, SIGNAL(finished()), ui->programPage, SLOT(setDone()));
connect(worker, SIGNAL(updateProgress(int)), this, SLOT(updateWritingProgressBar(int)));
connect(worker, SIGNAL(finished()), ui->programPage, SLOT(setDone()));
connect(workerThread, SIGNAL(finished()), worker, SLOT(stop()), Qt::QueuedConnection);
}
FlashWizard::FlashWizard(QWidget *parent) : QWizard(parent), ui(new Ui::FlashWizard)
{
ui->setupUi(this);
ui->pbReading->reset();
ui->pbWriting->reset();
ui->lblReadingStatus->setText("");
ui->lblReadingStatus->setText("");
ui->lblProgStatus->setText("");
connect(ui->introPage, SIGNAL(p1_updateLabelOne(const QString&)), this, SLOT(updateLabel(const QString&)));
connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(pageCleanUp(int)));
worker = new Worker;
workerThread = new QThread;
worker->moveToThread(workerThread);
connect(workerThread, SIGNAL(started()), worker, SLOT(start()));
connect(worker, SIGNAL(finished()), workerThread, SLOT(quit()));
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater()));
connect(workerThread, SIGNAL(finished()), ui->programPage, SLOT(setDone()));
connect(worker, SIGNAL(updateProgress(int)), this, SLOT(updateWritingProgressBar(int)));
connect(worker, SIGNAL(finished()), ui->programPage, SLOT(setDone()));
connect(workerThread, SIGNAL(finished()), worker, SLOT(stop()), Qt::QueuedConnection);
}
To copy to clipboard, switch view to plain text mode
#include "worker.h"
#include <QThread>
#include <QDebug>
{
m_workerTimer
= new QTimer(this);
}
void Worker::start()
{
connect(m_workerTimer, SIGNAL(timeout()), this, SLOT(doWork()));
qDebug() << "Object constructor: " << thread();
m_workerTimer->start(100);
}
void Worker::stop()
{
m_workerTimer->stop();
emit finished();
}
void Worker::doWork()
{
for (int i = 0; i < 1000000; i++)
{
if (i % 10000 == 0)
{
emit updateProgress(i / 10000);
qDebug() << (i / 10000);
static_cast<MThread
*>
(QThread::currentThread())->msleep
(10);
}
}
emit updateProgress(100);
emit finished();
}
#include "worker.h"
#include <QThread>
#include <QDebug>
Worker::Worker(QObject *parent) : QObject(parent)
{
m_workerTimer = new QTimer(this);
}
void Worker::start()
{
connect(m_workerTimer, SIGNAL(timeout()), this, SLOT(doWork()));
qDebug() << "Object constructor: " << thread();
m_workerTimer->start(100);
}
void Worker::stop()
{
m_workerTimer->stop();
emit finished();
}
void Worker::doWork()
{
for (int i = 0; i < 1000000; i++)
{
if (i % 10000 == 0)
{
emit updateProgress(i / 10000);
qDebug() << (i / 10000);
static_cast<MThread*>(QThread::currentThread())->msleep(10);
}
}
emit updateProgress(100);
emit finished();
}
To copy to clipboard, switch view to plain text mode
Bookmarks