How to play music in a function until the end of the music to end the function ?
-
QSound::play
https://doc.qt.io/qt-5/qsound.html#play-1
to the end of the function
You cant control that.
play
will start its own loop and return immediately to the function where it was called. So if your music file is 3mins long, the music will still play, even if the function is not executed at that moment.You could use
QSoundEffect
and mute or stop the music when you reached the end of your function. -
Thank you both for your replies, I didn't express myself clearly, my mistake. I want to open a new thread for playing music, and when the music is finished, I can close the thread. The only way I can think of is to use QTimer to set a timer that counts down to the same amount of time as the music, and then listen to the timeout slot function to exit the thread. Is there a class that has a finished signal when the music finishes playing to do this?@artwaw @Pl45m4
-
This post is deleted!
-
This post is deleted!
-