以 n 秒为间隔调用函数 n 次

Call a function n times with an interval of n seconds

我想在 10 秒的间隔内简单地调用一个函数 4 次。 这只调用一次

    QTimer *timer = new QTimer(this);
    timer->setSingleShot(true);
    connect(timer, SIGNAL(timeout()), this, SLOT(myFunction()));
    timer->start(10000);

如果我去掉 setSingleShot 方法,它将永远被调用。有没有内置的方法只调用它 n 次。我在 Qt 文档中找不到它。

brute-force、non-scalable方式:启动四个定时器。

一个更实用的方法是让回调跟踪它被调用了多少次,然后在第四次调用时停止计时器。