PDA

View Full Version : Do I have to release the resource when using Phonon::createPlayer()?



furskytl
17th September 2011, 14:38
I am not familiar with the phonon.And following the advice of Qt documents,I use it in a function like this:

Phonon::MediaObject *music ;
music = Phonon::createPlayer(Phonon::MusicCategory,Phonon: :MediaSource(pathName));
music->play();

I will call this function with different pathName to play different music.I am afraid that maybe everytime I call Phonon::createPlayer(),it will create something in the memory,and it need to be deleted manually.
Am I right?Or what's the right way to use it?Thanks very much!

kornicameister
18th September 2011, 03:17
I've never used Phonon...but according to the code You posted -> Yes, you need to do

delete music;
music = 0;

because this, I believe static method, Phonon::createPlayer(Phonon::MusicCategory,Phonon: :MediaSource(pathName));
returns a pointer which You assign to music ptr, therefore I believe that You have to delete it manually and not rely on Phonon's internal objects manipulations

furskytl
18th September 2011, 12:21
Yes,at last I make "music" a variable declared outside the function,and i manually call function stop() and clear().