QT使用Timer

void MainWindow::initTimer()
{
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(timerRecalc()));
    timer->start(1000*6);
}


void MainWindow::timerRecalc()
{
    for(int i=0;i<eventArray->size();i++)
    {
        NMyEvent myEvent = eventArray->at(i);
        ui->tableMain->setItem(i, 0, new QTableWidgetItem(myEvent.EventName));
        ui->tableMain->setItem(i, 1, new QTableWidgetItem(NMyUtils::formatDate(myEvent.TimeBegin)));
        ui->tableMain->setItem(i, 2, new QTableWidgetItem(NMyUtils::formatDate(myEvent.TimeDue)));
        myEvent.reCalcDaysLeft();
        ui->tableMain->setItem(i, 3, new QTableWidgetItem(myEvent.DaysLeft));
        ui->tableMain->setItem(i, 4, new QTableWidgetItem(myEvent.Comments));
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*