Qt World Summit: Submit your Presentation


  • Dear QTDevs,
    I am struggeling with the QMediaPlayer. I can play songs and stop them. But the song has 40s and I want to use it as a notification sound. So i should only play for 8 sec and then stops. I tried some things with sleep() or delay. But it is not working and i thought there would be a way to do it more neat.

    Thanks a lot,

  • Lifetime Qt Champion


    For that kind of usage QSound should be used. Take a look at the audio file type constraints.

  • What command is it there cant find anything

  • Lifetime Qt Champion


    There is no PlayPart or similar. You will have to call stop on it when you want it to stop before its
    actual duration.

    Some way could be.
    Note the use of static. if you only need this in one Form
    i would make QSound s a member and the function a member also.
    However, this is contained in a function using a lambda for compactness.

    void PlayNoti(int duration = 8000) /*msec*/
        static QSound s("mysounds/bells.wav");
        QTimer::singleShot(duration, []() {

  • thanks mate !!!!

Log in to reply