I've make a player with a playlist. For playing songs i'm using "play" which i start in a QProcess which runs inside the QThread. The code looks like this:
Qt Code:
  1. jBoxPlayer::jBoxPlayer(QListBox *&playlist)
  2. {
  3. _pPlayList = playlist;
  4. _pPlayer = new QProcess(0,"jPlayer");
  5. }
  6.  
  7. jBoxPlayer::~jBoxPlayer()
  8. {
  9. _pPlayList=NULL;
  10. delete _pPlayer;
  11. }
  12.  
  13. void jBoxPlayer::run()
  14. {
  15. QLBItemExt *lb;
  16. int i=0;
  17.  
  18. while (1)
  19. {
  20. // qDebug(QString("loop"));
  21. if ((_pPlayList->count()==0) || _pPlayer->isRunning()) continue;
  22. // if (_pPlayList->count()>0) {QString("if Playlist.");}
  23. // if ( _pPlayer->isRunning()) continue;
  24.  
  25.  
  26. qDebug("Playing new song.");
  27. _pPlayer->clearArguments();
  28. lb = (QLBItemExt *)_pPlayList->item(i++);
  29. _pPlayer->addArgument("play");
  30. qDebug(QString("Playing: %1").arg(lb->GetPath()));
  31. _pPlayer->addArgument(lb->GetPath());
  32. lb=NULL;
  33. // mutex.lock();
  34. // _pPlayList->removeItem(0);
  35. // mutex.unlock();
  36. _pPlayer->start();
  37. //_bPlaying=true;
  38. qDebug("loop end.");
  39. }
  40. qDebug("i'm out");
  41. }
To copy to clipboard, switch view to plain text mode 

the playlist is populated whit 2 songs. When i run the app the player plays well the first song. but when finished playing it throw an segmentation fault. The problem is when i uncoment the line 20,22,23 and comment line 21 it works fine - whitout the segmentation fault.
i have no experience with QThreads and QProcess and i don't know if the while(1) is the right approach (the signal processExited() it should be a better way i think) for the player to play untill the end of the playlist.

Any help on pointing me to the right direction would be great. or how in the real world threads and process are handled