Hello. I want to do a litte music player based on phonon libs.

I want to make another class with operations like play, stop etc.
Qt Code:
  1. #include "plik.h"
  2.  
  3. #include <QString>
  4. #include <QDebug>
  5.  
  6. #include <phonon/Global>
  7. #include <phonon/MediaObject>
  8. #include <phonon/AudioOutput>
  9. #include <phonon/MediaSource>
  10. #include <phonon/Path>
  11.  
  12.  
  13. Phonon::MediaObject *mediaObject;
  14. Phonon::AudioOutput *audioOutput;
  15.  
  16.  
  17. Plik::Plik()
  18. {
  19. this->next = NULL;
  20. this->prev = NULL;
  21. }
  22.  
  23. void Plik::setPath(QString path)
  24. {
  25. this->path = path;
  26. return;
  27. }
  28.  
  29. QString Plik::returnPath()
  30. {
  31. return this->path;
  32. }
  33.  
  34. void Plik::playFile()
  35. {
  36. mediaObject = new Phonon::MediaObject(this);
  37. audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
  38.  
  39. mediaObject->setCurrentSource(Phonon::MediaSource("/home/matulik/test.mp3"));
  40. audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
  41. Phonon::Path path = Phonon::createPath(mediaObject,audioOutput);
  42.  
  43. mediaObject->setTickInterval(1000);
  44. audioOutput->setVolume(100);
  45. audioOutput->setMuted(FALSE);
  46. mediaObject->play();
  47.  
  48. }
To copy to clipboard, switch view to plain text mode 

And in mainwindow:
Qt Code:
  1. Plik p1;
  2. p1.playFile();
To copy to clipboard, switch view to plain text mode 

And this doesnt work.

I dont know where is the problem, becouse the same source code coping to mainwindow works..

Qt Code:
  1. #include "odplayer.h"
  2. #include "ui_odplayer.h"
  3. #include "plik.h"
  4.  
  5. #include <QString>
  6. #include <QDebug>
  7.  
  8. #include <phonon/Global>
  9. #include <phonon/MediaObject>
  10. #include <phonon/AudioOutput>
  11. #include <phonon/MediaSource>
  12. #include <phonon/Path>
  13.  
  14.  
  15. Phonon::MediaObject *mediaObject;
  16. Phonon::AudioOutput *audioOutput;
  17.  
  18.  
  19. odplayer::odplayer(QWidget *parent) :
  20. QMainWindow(parent),
  21. ui(new Ui::odplayer)
  22. {
  23. ui->setupUi(this);
  24.  
  25. mediaObject = new Phonon::MediaObject(this);
  26. audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
  27.  
  28. mediaObject->setCurrentSource(Phonon::MediaSource("/home/matulik/test.mp3"));
  29. audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
  30. Phonon::Path path = Phonon::createPath(mediaObject,audioOutput);
  31.  
  32. mediaObject->setTickInterval(1000);
  33. audioOutput->setVolume(100);
  34. audioOutput->setMuted(FALSE);
  35. mediaObject->play();
  36. }
  37.  
  38. odplayer::~odplayer()
  39. {
  40. delete ui;
  41. }
To copy to clipboard, switch view to plain text mode 

Someone can help?