Hello !
so i have this function in a class that plays an audio file and stops it if it's being active.

This is the class and its function :
Qt Code:
  1. #include "soundeffects.h"
  2. #include <QMediaPlayer>
  3. #include <QMediaPlaylist>
  4.  
  5. // klas sound effectov sm naredu in potem jih sam klicm ko jih rabm na primer ko pritisnem SPACE se zazene
  6. // canonBallShot funkcija in sound effect ki se nahaj v tej funkciji;
  7.  
  8. SoundEffects::SoundEffects(){
  9. soundEffect = new QMediaPlayer;
  10. }
  11.  
  12. void SoundEffects::playPlaneEngineSound(){
  13.  
  14. soundEffect->setMedia(QUrl("qrc:/Story_Sounds/PlaneEngine.wav"));
  15.  
  16. if(soundEffect->state() == QMediaPlayer::PlayingState){
  17. soundEffect->stop();
  18. }else if(soundEffect->state() == QMediaPlayer::StoppedState){
  19. soundEffect->play();
  20. }
  21. }
To copy to clipboard, switch view to plain text mode 

I call the function in game.cpp 3 times like this:
Qt Code:
  1. soundEffects->playPlaneEngineSound();
  2. soundEffects->playPlaneEngineSound();
  3. SoundEffects->playPlaneEngineSound();
To copy to clipboard, switch view to plain text mode 
and the application crashes and i don't know why...
Could it be because i set media again when the function is called the third time ?
And if how do i fix it so that when i call the function once, it plays the sound, second time it stops it and so on ( checking if it's active or not and depending on the output the audio is played or stopped ).