Sound
-
i know how to do it in qml.....not in qt c++...
here goes...
use a Timer....where onTrigger of that state(in Qml) the music starts playing...and when closing the app...u dont have to stop the music there because when u kill the application...everything shuts down.
1.) use an import called
import QtMultimediaKit 1.12.) then.....
add the sound file to your project folder ie. in the qml folder(urproject/qml/sounds/)....
then use that in your application...
by using this code....@Audio{
id:menusound
source:"sounds/electropoly.mp3"
}@3.) then use a timer to make that file work in your app...
@Timer{
id:soundtimer
interval:1;
repeat:true;
running:false;
onTriggered: menusound.play();
}@4.) then use another timer or....an on clicked function(if u require) to call the file to play....
@Timer {
id:start;
interval: 1000;
running: false;
onTriggered: {
rect.state = "menu"; /* play the file after it comes to this state!! */
soundtimer.running = true;
}
}@dont forget to give ids to the timers u create or any object/item that you create....because it will be easier for you to use them else where in your code.