I was hoping to get some help figuring out where I went wrong on my code for a QThread. This is the first time doing threading and have been reading and watching tutorials, but am still hvaing a hard time. Herr is my code
currentTimeThread.h (my thread)
#ifndef CURRENTTIMETHREAD_H
#define CURRENTTIMETHREAD_H
#include <QtCore>
class currentTimeThread :public QThread
{
public:
currentTimeThread();
void run();
};
#endif // CURRENTTIMETHREAD_H
currentTimeThread.cpp
#include "currenttimethread.h"
#include <QtCore>
#include <QDebug>
#include "noheatmode.h"
currentTimeThread::currentTimeThread()
{
}
void currentTimeThread::run()
{
QTime time = QTime::currentTime();
QString sTime = time.toString("hh:mm:ss:ms");
noheatmode::ui->tempTimeNoHeatMode->append(sTime);
}
and my noHeatMode.cpp when the thread is called/started
#include "noheatmode.h"
#include "ui_noheatmode.h"
#include "wiringPi.h"
#include "currenttimethread.h"
#include <QTime>
#include <QTextEdit>
#include <QTimer>
#include <QString>
noheatmode::noheatmode(QWidget *parent) :
QWidget(parent),
ui(new Ui::noheatmode)
{
ui->setupUi(this);
}
noheatmode::~noheatmode()
{
delete ui;
}
while(flowTime > 0)
currentTimeThread timeThread;
timeThread.start();
{// set second pin LED to flash according to dutyCycle
digitalWrite(2,1);
delay(onTime);
digitalWrite(2,0);
delay(offTime);
//set zero pin to be high while flowtime is more than 0
digitalWrite(0,1);
flowTime--;
}
The issues it, I am getting an error that the timeThread of
currentTimeThread timeThread
is not declared. What is the issue?
You are misplaced the braces in your while loop:
Otherwise, the code is equivalent to this