Qt:如何重复声音x次与QtSound

Qt: How to repeat sound x times with QtSound

本文关键字:次与 QtSound 声音 何重复 Qt      更新时间:2023-10-16

我不确定我是否正确理解QSound。setLoop函数应该可以工作。

我想播放一些波文件3次。我试过下面的代码,但它只播放一次。

QSound soundObj(filePath);
soundObj.setLoops(3);
soundObj.play();

帮助:-)

编辑:该代码的完整版本如下所示

void Alarms::playSound(QString filePath)
{
    QSound soundObj(filePath);
    soundObj.setLoops(3);
    soundObj.play();
}

soundObj对象被快速销毁。
必须动态分配