#include "timeupdatethread.h"


TimeUpdateThread::TimeUpdateThread(QObject *parent) : QThread(parent)
{
    timer = new QTimer(this);
    connect(timer, &QTimer::timeout, [this]() {
        QDateTime currentDateTime = QDateTime::currentDateTime();
        QString currentTimeString = currentDateTime.toString("yyyy-MM-dd hh:mm:ss");
        emit timeUpdated(currentTimeString);
    });
}

void TimeUpdateThread::stop()
{
    isStopped = true;
    timer->stop();
    quit();
}
TimeUpdateThread::~TimeUpdateThread()
{
    stop();
    wait();
}
void TimeUpdateThread::run()
{

    timer->start(1000);

    QDateTime currentDateTime = QDateTime::currentDateTime();
    QString currentTimeString = currentDateTime.toString("yyyy-MM-dd hh:mm:ss");
    emit timeUpdated(currentTimeString);
    exec();
}
