A
A
aeaeae12020-04-18 22:01:16
Qt
aeaeae1, 2020-04-18 22:01:16

How to display the countdown in the label?

How to make it so that the time count is displayed in the label, that's what I did, but it displays the current time for me

QTextStream in(&file);
    QTime start = QTime::currentTime();
    while (!in.atEnd())
    {
      QString line = in.readLine();
      if (line.contains(v) || line.contains(s) || line.contains(k) || line.contains(m) || line.contains(q) || line.contains(r))
        ui.textEdit->append(line);
      ui.lineEdit_6->setText(QString().number(ui.textEdit->document()->lineCount()));
    }
    QTime finish = QTime::currentTime();
    QString time;
    ui.label->setText((finish.toString("")));
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory, 2020-04-18
@aeaeae1

QTime::toString()for a timer it is better not to use. it is rather just for displaying the time in a specific format. To calculate the elapsed time, it is better to do this:

__int64 start = QDateTime::currentMSecsSinceEpoch();
    /*
     *
     *
     *
     *
     *
     */
    __int64 duration = QDateTime::currentMSecsSinceEpoch() - start;
    ui->label->setText(QString::number(duration));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question