Мой счетчик QThread дает сбой, давая странные результаты для того, каким должно быть число, поскольку поток правильно считает, но в функции SetLabel я получаю значение, отличное от того, что указано в QThread, и после 3 секунд происходит сбой, и метка, похоже, не обновляется. .
QThread* CountThread = new QThread;
Counter* Count = new Counter();
Count->moveToThread(CountThread);
connect(CountThread, SIGNAL(started()), Count, SLOT(Process()));
connect(Count, &Counter::SecondsUpdate, this, [=]{ SetLabel(Count->Seconds) ;});
connect(Count, SIGNAL(finished()), CountThread, SLOT(quit()));
CountThread->start();
void Counter::Process()
{
int secs = 0;
while (secs < 1000)
{
qDebug() << "hello" << secs;
secs += 1;
Sleep(1000);
emit SecondsUpdate();
}
emit finished();
}
void BaseWindow::SetLabel(int Seconds)
{
qDebug() << Seconds;
this->Test->setText(QString("Seconds: " + QString::number(Seconds)));
}
class Counter : public QObject
{
Q_OBJECT
public slots:
void Process();
signals:
void finished();
void SecondsUpdate();
public:
int getValue() { return Seconds;}
int Seconds;
};
РЕДАКТИРОВАТЬ: Кажется, проблема заключается в изменении метки, как я прокомментировал это-> Text-> setText, и он не вылетел