PDA

View Full Version : Read xml file (advanced)



prophet0
15th November 2011, 00:34
So i have an XML File



<root>
<row>
<id>1</id>
<movie>e32017e61f189944fe1bf703ebc14050.avi</movie>
</row>
<row>
<id>2</id>
<movie>e3535645kds54544fe1bf703ebc14050.avi</movie>
</row>
</root>


I want to read threw the xml file and set the value of <movie> to a string
then set the string to read the next one on a timer for phonon like SIGNAL abouttofinish to SLOT next-movie-string-from-xml

i have been working on this for a few weeks now and still cant get any solution

please any light on this would be amazing thanks

ChrisW67
15th November 2011, 01:57
You want to load the play list XML file and provide a function that returns the next movie file name every time it is called. This should be trivial with QDomDocument and QDomDocument::elementsByTagName()

What have you tried?

prophet0
15th November 2011, 20:25
Well what i have now that is working....



QFile xmlfile("/home/development/ttm/moives/xml/strings.xml");
if (xmlfile.open(QIODevice::ReadOnly)) {
QXmlStreamReader xml(&xmlfile);
while (!xml.atEnd()) {
xml.readNext();
if (xml.isStartElement() && xml.name() == "movie") {
ui->debugMovie->setText(xml.readElementText());

}
}

}else {
ui->debugMovie->setText("Not Reading xmlFile");
}



then to get the text and set the file name i use



QString movFiledb = ui->debugMovie->text();


then to set the phonon movie and stuff



QString vidpath = QApplication::applicationDirPath();
vidpath = "/home/development/ttm/moives/";
obj_mediaobject->enqueue(Phonon::MediaSource(vidpath + movFiledb));


then when i play the movie it takes the movie tag thats string is e32017e61f189944fe1bf703ebc14050.avi

now how would i be able to use the code i have but make a signal about to finish and then read the next movie tag from xml ?

d_stranz
15th November 2011, 20:51
Why not just simply read in the entire list of movies into a QStringList or something like that, then iterate over the list of file names? There is no need for the reading of the XML file to be coupled to the playing of the movies. It just makes your code harder to understand, debug, and modify if all these different and unrelated things are happening together.

As for the signal, if you are using phonon VideoPlayer, there is a finished() signal you can connect to.

prophet0
15th November 2011, 21:00
Sorry i forgot to say that i am still learning Qt and only been programming for about 4 months so a lot of this is new to me could you please show an example

thanks

d_stranz
15th November 2011, 21:37
Try this link: http://twolinux.blogspot.com/2010/10/writing-simple-media-player-in-qt.html

I don't have an example myself.

prophet0
15th November 2011, 21:53
thanks ill try that.. i will also look into qstringlist