1. The QTimeerEvent class is used to describe a timer event. For a subclass of QObject, you only need to use the ingQobject:: startTimer(int interval) function to start a timer. This function needs to input a certificate in milliseconds as a parameter to indicate the set event, and the function returns an integer The label to represent this timer. When this timer overflows, you can perform the required operations in the timerEvent() function
id1 = startTimer ( 1000 );
void Widget::timerEvent(QTimerEvent*event)
{
if (event->timerId() == id1 ){ // Determine which timer it is
qDebug() << "timer1";
}
else if (event->timerId() == id2) {
qDebug() << "timer2";
}
else {
qDebug() << "timer3";
}
}
2. The QTimer class implements a timer, which provides higher-level programming interfaces, such as signals and slots, and can also set a timer that runs once. (take the signal slot)
QTimer *timer = new QTimer ( this ); //Create a new timer
// Associate the overflow signal of the timer to the slot
connect(timer, &QTimer::timeout, this,&Widget::timerUpdate);
timer->start( 1000 ); // Set the overflow time to 1 second and start the timer
3. Regarding random numbers, QT is implemented by qrand and qsrand