2013-04-28 96 views
0

我有播放mp3的QT應用程序。QT,運行特定時間的功能

當我調用play()函數時,它播放音樂直到mp3結束。但是,我想玩2秒。

player->play(); 
//after 2 seconds 
player->stop(); 

我該如何控制播放和停止之間的時間?

回答

2

使用QTimer::singleShot。如果您的播放器有一個名爲stop()的插槽,請使用如下所示的單次計時器:

player->start(); 
QTimer::singleShot(2000, player, SLOT(stop()));