Hello. I try make a music player with play lists in tabs.
I saved open play lists when program is closing to temp file and i want load it on startup.
tmp file looks like this:
Qt Code:
  1. play list name 1
  2. file 1
  3. file 2
  4. file 3
  5. separator
  6. play list name 2
  7. file 1
  8. file 2
  9. etc.
To copy to clipboard, switch view to plain text mode 
i have struct and i have load data to the struct
Qt Code:
  1. struct PLL
  2. {
  3. QString name;
  4. QList<Phonon::MediaSource> sources;
  5. };
  6.  
  7. void Window::load_on_start()
  8. {
  9. QFile file("tmp.txt");
  10. if(file.open(QFile::ReadOnly | QFile::Text))
  11. {
  12. QTextStream in(&file);
  13. QString line;
  14. PLL pl[1000];
  15. int indeX = 0;
  16. do{
  17. line = in.readLine();
  18. if(!line.isEmpty())
  19. {
  20. if(!line.contains("/"))
  21. {
  22. if(line == ">>>")
  23. indeX++;
  24. else
  25. pl[indeX].name = line;
  26. }
  27. else
  28. {
  29. Phonon::MediaSource source(line);
  30. pl[indeX].sources.append(source);
  31. }
  32.  
  33. }
  34. }while(!line.isEmpty());
  35.  
  36. qDebug() << indeX << pl[0].name << pl[0].sources.size();
  37. qDebug() << indeX << pl[1].name << pl[1].sources.size();
  38. for(int i = 0; i <= indeX; i++)
  39. {
  40. if(true == true) //!pl[i].sources.isEmpty()
  41. {
  42. sources.clear();
  43. int ind = sources.size();
  44. sources = pl[i].sources;
  45. tabWidget->setTabText(tabWidget->currentIndex(), pl[i].name);
  46. metaInfo->setCurrentSource(sources.at(0));
  47. qDebug() << "TEST = >" << ind << pl[i].name << sources.size() << sources.at(0).fileName();
  48. if(i < indeX) add_new_playList();
  49. }
  50. }
  51.  
  52. }
  53. file.close();
  54. }
  55.  
  56. void Window::metaInfoLoad(Phonon::State newState, Phonon::State)
  57. {
  58. if (newState == Phonon::ErrorState){
  59. QMessageBox::warning(this, "BÅ‚Ä…d podczas otwierania pliku", metaInfo->errorString());
  60.  
  61. while (!sources.isEmpty() && !(sources.takeLast() == metaInfo->currentSource())) {} /* loop */;
  62. return;
  63. }
  64.  
  65. if (newState != Phonon::StoppedState && newState != Phonon::PausedState)
  66. return;
  67.  
  68. QString icon;
  69.  
  70. if(metaInfo->currentSource().type() == Phonon::MediaSource::Invalid) icon = "2";
  71. else icon = "0";
  72.  
  73. QMap<QString, QString> metaData = metaInfo->metaData();
  74.  
  75. QString title = metaData.value("TITLE");
  76. if (title == "")
  77. title = metaInfo->currentSource().fileName();
  78.  
  79. QTime total(0, (metaInfo->totalTime() / 60000) % 60, (metaInfo->totalTime() / 1000) % 60);
  80. QString totalTime = total.toString("mm:ss");
  81.  
  82. int playListIndex = tabWidget->tabWhatsThis(tabWidget->currentIndex()).toInt();
  83.  
  84. QListWidgetItem *item = new QListWidgetItem(playList[playListIndex]);
  85. item->setText(title+"|"+totalTime+"|"+icon);
  86. item->setStatusTip(metaInfo->currentSource().fileName());
  87.  
  88. int index = sources.indexOf(metaInfo->currentSource()) + 1;
  89. if (sources.size() > index) {
  90. metaInfo->setCurrentSource(sources.at(index));
  91. }
  92. else return;
  93. }
To copy to clipboard, switch view to plain text mode 

It is work when i have one playlist. When i have more it set correct names for tabs but set item to qlistwidget only for last playlist : /

What i do wrong ?

PS. sorry for my English :P