diff --git a/CableTool/common.h b/CableTool/common.h index 30fa27d..0e06d43 100644 --- a/CableTool/common.h +++ b/CableTool/common.h @@ -33,8 +33,8 @@ * ******************************************************************************/ -#ifndef __COMMON_H__ -#define __COMMON_H__ +#ifndef __COMMON_H_ +#define __COMMON_H_ /* Includes ------------------------------------------------------------------*/ #include @@ -355,7 +355,7 @@ typedef struct uint8_t isTempCol; uint8_t isWaveCol; uint8_t APN[DEV_APN_LEN]; - uint8_t APN_long[DEV_APN_LEN_LONG]; + //uint8_t APN_long[DEV_APN_LEN_LONG]; } devConfig; /* 南网配置信息. */ diff --git a/CableTool/widget.cpp b/CableTool/widget.cpp index e131c65..e30be16 100644 --- a/CableTool/widget.cpp +++ b/CableTool/widget.cpp @@ -7,6 +7,8 @@ #include #include #include +#include + QWidget *ReadOnlyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { @@ -62,6 +64,10 @@ Widget::Widget(QWidget *parent) crc32_table_init(); + // 隐藏不用的页面 + //ui->tabWidget->setTabEnabled(ui->tabWidget->indexOf(ui->frequencyTab), false); + ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->frequencyTab)); + /* 配置校准页面表格 */ ui->adjustTable->horizontalHeader()->setVisible(true); ui->adjustTable->horizontalHeader()->resizeSection(0,20); @@ -129,30 +135,61 @@ Widget::Widget(QWidget *parent) /* 打开配置文件, 恢复关闭前的状态. */ QString file = QCoreApplication::applicationDirPath()+"/CableTool.ini"; settings = new QSettings(file, QSettings::IniFormat, this); -#if 0 for(int i = 0; i < ui->comboPort->count(); i++) { - if (!QString::compare(ui->comboPort->itemText(i), settings->value("usartBoxName", "COM1").toString(), Qt::CaseSensitive)) + if (QString::compare(ui->comboPort->itemText(i), settings->value("usartBoxName", "COM1").toString(), Qt::CaseSensitive) == 0) { ui->comboPort->setCurrentIndex(i); } } -#endif - ui->comboBaud->setCurrentIndex(settings->value("baudBoxIndex", 6).toInt()); - filePath = settings->value("updateFile", "").toString(); - adjFilePath = settings->value("adjFile", "").toString(); - waveFilePath = settings->value("waveFile", "").toString(); - QFileInfo fileinfo = QFileInfo(filePath); - ui->fileNameEdit->setText(fileinfo.fileName()); - ui->fileNameEdit->setReadOnly(true); - ui->fileTypeBox->setCurrentIndex(settings->value("updateFileType", 0).toInt()); - ui->freChBox->setCurrentIndex(settings->value("freChIndex", 0).toInt()); + + for (int i = 0; i < ui->comboBaud->count(); i++) + { + if (QString::compare(ui->comboBaud->itemText(i), settings->value("baudBoxIndex", "115200").toString(), Qt::CaseSensitive) == 0) + { + ui->comboBaud->setCurrentIndex(i); + } + } + ui->comboBaud->setCurrentIndex(11); + QString pcom = settings->value("usartBoxName").toString(); + qDebug() << "com:" << pcom << endl; + filePath = settings->value("updateFile", "").toString(); + adjFilePath = settings->value("adjFile", "").toString(); + waveFilePath = settings->value("waveFile", "").toString(); + QFileInfo fileinfo = QFileInfo(filePath); + ui->fileNameEdit->setText(fileinfo.fileName()); + ui->fileNameEdit->setReadOnly(true); + ui->fileTypeBox->setCurrentIndex(settings->value("updateFileType", 0).toInt()); + ui->freChBox->setCurrentIndex(settings->value("freChIndex", 0).toInt()); + + +#if 1 + //创建辅助线程, + m_thread = new QThread(this); + + //创建任务类,不能指定父指针为this,否则还是会在当前线程 + worker=new Worker; + //移动到线程 + worker->moveToThread(m_thread); + //绑定worker发射的信号,来更新ui界面的label + connect(worker,&Worker::changeString,this,&Widget::on_displayMessage); + + //绑定自定义的triggerWork信号,来触发worker的工作函数,工作函数就会在子线程中执行 + connect(this,&Widget::triggerWork,worker,&Worker::doWork); + + //手动启动线程 + m_thread->start(); + + qDebug()<<"主函数所在线程:"<frequencyTable->columnCount(); i++) + for(int i = 0; i < ui->frequencyTable->columnCount(); i++) { for(int j = 0; j < ui->frequencyTable->rowCount(); j++) { @@ -214,15 +251,29 @@ void Widget::serialErrHandle(QSerialPort::SerialPortError error) void Widget::serialDisconnect() { - deinitSerial(); - isConnected = 0; + deinitSerial(); + isConnected = 0; ui->btnConn->setText("连接"); - buttonEnable(FALSE); + buttonEnable(FALSE); +} + +void Widget::on_displayMessage(QString text) +{ + QMessageBox::critical(this, tr("Error"), text); + if (QString::compare(UART_COMMUNICATION_ERROR, text, Qt::CaseSensitive) == 0) + { + serialDisconnect(); + } } -int Widget::initSerial() +int Widget::openSerial() { + if (serialPort) + { + delete serialPort; + serialPort = nullptr; + } serialPort = new QSerialPort; serialPort->setPortName(ui->comboPort->currentText()); serialPort->setBaudRate(ui->comboBaud->currentText().toInt()); @@ -231,16 +282,14 @@ int Widget::initSerial() serialPort->setStopBits(QSerialPort::OneStop); serialPort->setFlowControl(QSerialPort::NoFlowControl); if (serialPort->open(QIODevice::ReadWrite)) - { // open success - connect(serialPort, &QSerialPort::errorOccurred, this, &Widget::serialErrHandle); + { // open success + connect(serialPort, &QSerialPort::errorOccurred, this, &Widget::serialErrHandle); connect(serialPort, &QSerialPort::readyRead, this, &Widget::readData); } - else - { // open failed - QMessageBox::critical(this, tr("Error"), serialPort->errorString()); - } - //serialPort->setBaudRate(ui->comboBaud->currentText().toInt()); - qDebug() << "baudrate:" << serialPort->baudRate(); + else + { // open failed + QMessageBox::critical(this, tr("Error"), serialPort->errorString()); + } //newTask = new QThread; //usartProtocol = new Protocol; @@ -257,12 +306,13 @@ int Widget::initSerial() int Widget::deinitSerial() { if (serialPort->isOpen()) - { - //disconnect(&serialPort, &QSerialPort::readyRead, this, &Widget::readData); - serialPort->waitForReadyRead(500); // Wait 0.5 second to read all the data. + { + //disconnect(&serialPort, &QSerialPort::readyRead, this, &Widget::readData); + serialPort->waitForReadyRead(100); // Wait 0.5 second to read all the data. serialPort->close(); - delete serialPort; - } + delete serialPort; + serialPort = nullptr; + } return 0; } @@ -277,47 +327,54 @@ int Widget::readData() char *buf = qarry.data(); int len = qarry.size(); - qDebug() << __FUNCTION__ << "LEN=" << len << endl; + //qDebug() << __FUNCTION__ << "LEN=" << len << "rxbufLen:" << rxbufLen << endl; //HexPrint(__FUNCTION__, buf, len); - if (len < 0 || len > USART_BUF_SIZE) + if (len < 0 || static_cast(len) > USART_BUF_SIZE) { - rxbufLen = 0; - return -1; + rxbufLen = 0; + qDebug() << __FUNCTION__ << ":" << __LINE__ << "data is error.\n"; + return -1; } if (len + rxbufLen > USART_BUF_SIZE) { - rxbufLen = 0; - return -1; + rxbufLen = 0; + qDebug() << __FUNCTION__ << ":" << __LINE__ << "data is error.\n"; + return -1; } - memcpy(rxbuf + rxbufLen, buf, len); + memcpy(rxbuf + rxbufLen, buf, static_cast(len)); rxbufLen += len; - if (rxbufLen < sizeof(proto_head_t)) + if (static_cast(rxbufLen) < sizeof(proto_head_t)) { - return -1; + //qDebug() << __FUNCTION__ << ":" << __LINE__ << "data is error.\n"; + return -1; } - proto_head_t *header = reinterpret_cast(rxbuf); - //qDebug() << "header->len:" << header->len << endl; - if (rxbufLen != header->len + 4) - return -1; - - /* CRC32 校验. */ - if (crc32(rxbuf, header->len) != (*reinterpret_cast(rxbuf + header->len))) - { - qDebug() << "Bad data,throw it away.\n"; - rxbufLen = 0; - return -1; - } - - //printHexArray(__FUNCTION__, buf, len); - //HexPrint(__FUNCTION__, rxbuf, (header->len + 4)); + proto_head_t *header = reinterpret_cast(rxbuf); + //qDebug() << "header->len:" << header->len << " " << "rxbufLen:" << rxbufLen << endl; + if (rxbufLen != header->len + 4) + { + //qDebug() << __FUNCTION__ << ":" << __LINE__ << "data is error.\n"; + return -1; + } + /* CRC32 校验. */ + if (crc32(rxbuf, header->len) != (*reinterpret_cast(rxbuf + header->len))) + { + qDebug() << "Bad data,throw it away.\n"; + rxbufLen = 0; + return -1; + } + rxbufLen = 0; + + //printHexArray(__FUNCTION__, buf, len); + //HexPrint(__FUNCTION__, rxbuf, (header->len + 4)); paraseProtocols(rxbuf); - rxbufLen = 0; + + //qDebug() << "end rxbufLen = " << rxbufLen << endl; } qarry.clear(); @@ -489,6 +546,7 @@ void Widget::uiDevInfoRefresh() void Widget::uiDevConfigRefresh() { + qDebug() << __FUNCTION__ << "flag:" << clientDevConfig.flag << endl; if (IS_MONITOR_BIT_SET(clientDevConfig.flag, DEV_FLAG_CLI)) { ui->debugModeBox->setCurrentIndex(0); @@ -525,7 +583,7 @@ void Widget::uiDevConfigRefresh() ui->normalSleepBox->setCurrentIndex(0); } - ui->APNEdit->setText(QString(reinterpret_cast(clientDevConfig.APN_long))); + //ui->APNEdit->setText(QString(reinterpret_cast(clientDevConfig.APN_long))); ui->colIntervalEdit->setText(QString::number(clientDevConfig.collectInterval)); ui->waveIntervalEdit->setText(QString::number(clientDevConfig.waveInterval)); @@ -745,6 +803,7 @@ void Widget::protoContact(char *data) memcpy(&clientDevInfo, pbody, sizeof(devInfo)); uiDevInfoRefresh(); buttonEnable(true); + worker->timeCounterReset(); } void Widget::protoConfig(char *data) @@ -931,16 +990,44 @@ int Widget::protoManualAdjust(char *data) return 0; } -int Widget::protoAdjustInfo(char *data) +int Widget::protoAdjustInfoGet(char *data) { /* 获取参数. */ memcpy(&clientAdjInfo, data + sizeof(proto_head_t), sizeof(dev_adj_t)); /* 更新界面. */ - protoManualAdjust(data); + uiAdjustInfoRefresh(); + return 0; +} + +int Widget::protoAutoAdjust(char *data) +{ + int32_t rv = *reinterpret_cast(data + sizeof(proto_head_t)); + + /* 跳转状态. */ + //if (work) + { + //work->stateSet(CM_usart::WS_ADJ_INFO_GET); + //work->mutexUnlock(); + } + + sendMsgDeviceAdjustInfoGet(); + buttonEnable(true); + + /* 判断返回值. */ + if (0 == rv) + { + QMessageBox::information(this, "SUCCEED", "校准完成.", QMessageBox::Ok); + } + else + { + QMessageBox::warning(this, "WARNING", "校准失败!", QMessageBox::Ok); + } + return 0; } + int Widget::protoLog(char * data) { mul_head_t *header = reinterpret_cast(data + sizeof(proto_head_t)); @@ -1097,19 +1184,19 @@ int Widget::paraseProtocols(char *data) { proto_head_t *header = reinterpret_cast(data); - //qDebug() << "cmd_type:" << header->cmd_type << "cmd:" << header->cmd << endl; - //qDebug() << "len:" << header->len << endl; + qDebug() << "cmd_type:" << header->cmd_type << "cmd:" << header->cmd << endl; + qDebug() << "len:" << header->len << endl; if (DEBUG_CT_REPLY == header->cmd_type) { /* 共有命令处理. */ switch (header->cmd) { case DEBUG_C_CONTACT: // 获取配置成功后更新页面 - protoContact(data); - break; - + protoContact(data); + break; + case DEBUG_C_DEV_INFO_SET: - break; + break; case DEBUG_C_RESET: //_debug_pkt_reset(); break; @@ -1118,11 +1205,11 @@ int Widget::paraseProtocols(char *data) break; case DEBUG_C_UPDATE_APP: case DEBUG_C_UPDATE_IAP: - protoUpdateReply(data, header->cmd); - break; + protoUpdateReply(data, header->cmd); + break; case DEBUG_C_DEV_CONFIG: // 获取配置成功后更新页面 - protoConfig(data); - break; + protoConfig(data); + break; case DEBUG_C_DEV_CONFIG_SET: //buttonEnable(false); //snedMsgDeviceInfoGet(); @@ -1146,14 +1233,14 @@ int Widget::paraseProtocols(char *data) protoWaveDataUploadReply(data); break; case DEBUG_PRV_ADJ_INFO: - protoAdjustInfo(data); + protoAdjustInfoGet(data); break; case DEBUG_PRV_ADJ_INFO_SET: /* 更新界面. */ QMessageBox::information(this, "SUCCEED", "操作完成.", QMessageBox::Ok); break; case DEBUG_PRV_ADJ_AUTO: - //_debug_pkt_adj_auto(); + protoAutoAdjust(data); break; case DEBUG_PRV_DEV_STATE: protoState(data); @@ -1183,16 +1270,17 @@ int Widget::paraseProtocols(char *data) break; } } + return 0; } int Widget::snedMsgDeviceInfoGet() { - char buf[2048] = {0}; + char buf[2048] = {0}; uint32_t *crc = nullptr; proto_head_t *header = reinterpret_cast(buf); protoHeaderInit(header, sizeof(proto_head_t), 0xFFFFFFFF, DEBUG_CT_REQUEST, DEBUG_C_CONTACT); - header->dev_type_m = 1; + header->dev_type_m = 2; header->dev_type_s = 255; /* 计算校验和. */ @@ -1200,7 +1288,7 @@ int Widget::snedMsgDeviceInfoGet() *crc = crc32(buf, header->len); //printHexArray(__FUNCTION__, buf, header->len + 4); - //HexPrint(__FUNCTION__, buf, header->len + 4); + HexPrint(__FUNCTION__, buf, header->len + 4); writeData(buf, header->len + 4); return 0; } @@ -1502,7 +1590,7 @@ int Widget::sendMsgDeviceAdjustInfoGet() return 0; } -int Widget::sendMsgDeviceAdjustMode(int cmd) +int Widget::sendMsgDeviceAdjustMode(uint8_t cmd, adjSet *param) { char buf[2048] = {0}; uint32_t *crc = nullptr; @@ -1512,7 +1600,7 @@ int Widget::sendMsgDeviceAdjustMode(int cmd) /* 初始化报文头. */ protoHeaderInit(header, sizeof(proto_head_t) + sizeof(adjSet), clientDevInfo.id, DEBUG_CT_PRV_REQUEST, cmd); - memcpy(pdata, &clientAdjSet, sizeof(adjSet)); + memcpy(pdata, param, sizeof(adjSet)); /* 计算校验位. */ crc = reinterpret_cast(buf + header->len); @@ -1613,24 +1701,37 @@ int Widget::sendMsgHistoryDataGet() void Widget::on_btnConn_clicked() { - if (!isConnected) - { - initSerial(); - /* 变更按钮文字. */ + qDebug() << "1###isConnected =" << isConnected << endl; + if (!isConnected) + { + /* 保存串口配置. */ + if (QString::compare(settings->value("usartBoxName").toString(), ui->comboPort->currentText(), Qt::CaseSensitive) != 0) + { + settings->setValue("usartBoxName", ui->comboPort->currentText()); + } + + if (QString::compare(settings->value("baudBoxIndex").toString(), ui->comboBaud->currentText(), Qt::CaseSensitive) != 0) + { + settings->setValue("baudBoxIndex", ui->comboBaud->currentText()); + } + openSerial(); + /* 变更按钮文字. */ ui->btnConn->setText("断开"); - snedMsgDeviceInfoGet(); - isConnected = 1; - } - else - { - serialDisconnect(); - } + snedMsgDeviceInfoGet(); + isConnected = 1; + worker->timeCounterStart(); + } + else + { + serialDisconnect(); + } + qDebug() << "2###isConnected =" << isConnected << endl; } void Widget::on_btnReset_clicked() { - sendMsgDeviceReset(); - serialDisconnect(); + sendMsgDeviceReset(); + serialDisconnect(); } @@ -1824,7 +1925,7 @@ void Widget::on_configSetButton_clicked() clientDevConfig.energyMode = static_cast(ui->energyModeBox->currentIndex()); clientDevConfig.normalSleep = static_cast(ui->normalSleepBox->currentIndex()); memset(clientDevConfig.APN, 0, DEV_APN_LEN); - stringToChar(ui->APNEdit->text(), reinterpret_cast(clientDevConfig.APN_long), DEV_APN_LEN_LONG); + //stringToChar(ui->APNEdit->text(), reinterpret_cast(clientDevConfig.APN_long), DEV_APN_LEN_LONG); clientDevConfig.collectInterval = ui->colIntervalEdit->text().toUShort(); clientDevConfig.waveInterval = ui->waveIntervalEdit->text().toUShort(); @@ -2131,7 +2232,7 @@ void Widget::on_manualAdjButton_clicked() /* 下发配置. */ buttonEnable(false); - sendMsgDeviceAdjustMode(DEBUG_PRV_ADJ_MANUAL); + sendMsgDeviceAdjustMode(DEBUG_PRV_ADJ_MANUAL, &adj); } @@ -2324,7 +2425,7 @@ void Widget::on_adjButton_clicked() /* 下发配置. */ buttonEnable(false); - sendMsgDeviceAdjustMode(DEBUG_PRV_ADJ_AUTO); + sendMsgDeviceAdjustMode(DEBUG_PRV_ADJ_AUTO, &adj); } void Widget::on_tabWidget_tabBarClicked(int index) @@ -2332,6 +2433,35 @@ void Widget::on_tabWidget_tabBarClicked(int index) qDebug() << "index" << index << endl; if (index == 6) { - uiAdjustInfoRefresh(); + uiAdjustInfoRefresh(); } } + +void Widget::closeEvent(QCloseEvent* ev) +{ + //关闭事件中 停掉子线程 + worker->Stop();//终止工作函数 + m_thread->exit();//线程退出事件循环 + m_thread->wait();//等待线程退出 + qDebug()<<"线程退出了"; +} + +void Worker::doWork() +{ + //打印下线程id,看和主线程的线程id是否一样 + qDebug()<<"工作函数所在线程:"< m_timestamp + 1000) + { + if (m_timeCounterStat) + { + m_timeCounterStat = CNT_RST; + emit changeString(tr(UART_COMMUNICATION_ERROR)); + } + } + QThread::msleep(20); + } +} + diff --git a/CableTool/widget.h b/CableTool/widget.h index 4dd781e..f6ba762 100644 --- a/CableTool/widget.h +++ b/CableTool/widget.h @@ -5,15 +5,19 @@ #include #include #include +#include #include +#include #include "common.h" namespace Ui { //新增的 class form; } +class Worker; #define USART_BUF_SIZE 1088 +#define UART_COMMUNICATION_ERROR "communication timeout" /* 设置tableview某行/列不可编辑. */ class ReadOnlyDelegate: public QItemDelegate @@ -33,6 +37,10 @@ class Widget : public QWidget public: Widget(QWidget *parent = nullptr); ~Widget(); + +signals: + void triggerWork(); + private slots: void on_btnConn_clicked(); @@ -93,90 +101,95 @@ private slots: void on_adjButton_clicked(); void on_tabWidget_tabBarClicked(int index); + + void on_displayMessage(QString text); +protected: + void closeEvent(QCloseEvent* ev) override; private: - QString toHexadecimal(const QByteArray &byteArray); int searchUsablePort(); void serialErrHandle(QSerialPort::SerialPortError error); void serialDisconnect(); - int initSerial(); + int openSerial(); int deinitSerial(); int readData(); int writeData(char *buf, int len); - + int protoHeaderInit(proto_head_t * header, uint16_t len, uint32_t id, uint8_t cmd_type, uint8_t cmd); - - void buttonEnable(bool flag); - - QString devStateWaveStateGet(uint8_t state); - - QString devStateWlStateGet(uint8_t state); + + void buttonEnable(bool flag); + + QString devStateWaveStateGet(uint8_t state); + + QString devStateWlStateGet(uint8_t state); void uiDevInfoRefresh(); void uiDevConfigRefresh(); void uiDevCsgConfigRefresh(); - void uiDevRealDataRefresh(); - - void uiDevStateRefresh(); - - void uiPowerFrequencyRefresh(); - - void uiManualAdjustRefresh(); - - void uiAdjustInfoRefresh(); - - void protoContact(char *data); - - void protoConfig(char *data); - - void protoCsgConfig(char *data); - - void protoRealdata(char *data); - - int protoUpdateReply(char *data, int fileType); - - int protoWaveDataUploadReply(char *data); - - int protoPowerFrequency(char *data); - - int protoState(char *data); - - int protoManualAdjust(char *data); - - int protoAdjustInfo(char *data); - - int protoLog(char * data); - - int protoHistoryData(char *data); - + void uiDevRealDataRefresh(); + + void uiDevStateRefresh(); + + void uiPowerFrequencyRefresh(); + + void uiManualAdjustRefresh(); + + void uiAdjustInfoRefresh(); + + void protoContact(char *data); + + void protoConfig(char *data); + + void protoCsgConfig(char *data); + + void protoRealdata(char *data); + + int protoUpdateReply(char *data, int fileType); + + int protoWaveDataUploadReply(char *data); + + int protoPowerFrequency(char *data); + + int protoState(char *data); + + int protoManualAdjust(char *data); + + int protoAutoAdjust(char *data); + + int protoAdjustInfoGet(char *data); + + int protoLog(char * data); + + int protoHistoryData(char *data); + int paraseProtocols(char *data); int snedMsgDeviceInfoGet(); int sendMsgDeviceInfoSet(); int sendMsgDeviceReset(); - int sendMsgDeviceCfgDefault(); + int sendMsgDeviceCfgDefault(); int sendMsgDeviceConfigSet(); int sendMsgDeviceConfigGet(); int sendMsgDeviceCsgConfigGet(); - int sendMsgDeviceCsgConfigSet(); - int sendMsgDeviceRealDataGet(); + int sendMsgDeviceCsgConfigSet(); + int sendMsgDeviceRealDataGet(); int sendMsgDeviceUpdate(int fileType); - int sendMsgDeviceWaveDataGet(); - - int sendMsgDeviceStateGet(); - - int sendMsgDevicePowerFrequencyGet(); - - int sendMsgDeviceAdjustInfoGet(); - - int sendMsgDeviceAdjustInfoSet(); - - int sendMsgDeviceAdjustMode(int cmd); - - int sendMsgWaveCol(); - - int sendMsgWaveCal(); + int sendMsgDeviceWaveDataGet(); + + int sendMsgDeviceStateGet(); + + int sendMsgDevicePowerFrequencyGet(); - int sendMsgLogGet(); + int sendMsgDeviceAdjustInfoGet(); + + int sendMsgDeviceAdjustInfoSet(); + + int sendMsgDeviceAdjustMode(uint8_t cmd, adjSet *param); + + int sendMsgWaveCol(); + + int sendMsgWaveCal(); + + int sendMsgLogGet(); int sendMsgHistoryDataGet(); @@ -186,11 +199,9 @@ private: QString filePath; QString adjFilePath; QString waveFilePath; - //QThread *newTask; - //Protocol *usartProtocol; char rxbuf[USART_BUF_SIZE]; - int rxbufLen; + int rxbufLen; devInfo clientDevInfo; devConfig clientDevConfig; @@ -216,9 +227,58 @@ private: uint32_t dataIndex; int32_t logSum; int32_t historyDataSum; - ReadOnlyDelegate* readOnlyDelegate; + QThread *m_thread; + Worker *worker; +}; + + +#include + +class Worker : public QObject +{ + Q_OBJECT +public: + Worker() = default; + ~Worker() = default; + + enum CntStat + { + CNT_RST = 0, + CNT_START = 1, + }; + Q_ENUM(CntStat) + + //工作函数,在这个函数中编写业务逻辑 + void doWork(); + + //终止循环,结束工作函数 + void Stop() + { + stop=true; + } + + void timeCounterStart() + { + m_timestamp = QDateTime::currentMSecsSinceEpoch(); + m_timeCounterStat = CNT_START; + } + + void timeCounterReset() + { + m_timeCounterStat = CNT_RST; + } +signals: + void changeString(QString text); + +private: + bool stop = false; + +private: + QThread m_pTh; + qint64 m_timestamp; + CntStat m_timeCounterStat; };