Results 1 to 7 of 7

Thread: Read xml file (advanced)

  1. #1
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Exclamation Read xml file (advanced)

    So i have an XML File

    Qt Code:
    1. <root>
    2. <row>
    3. <id>1</id>
    4. <movie>e32017e61f189944fe1bf703ebc14050.avi</movie>
    5. </row>
    6. <row>
    7. <id>2</id>
    8. <movie>e3535645kds54544fe1bf703ebc14050.avi</movie>
    9. </row>
    10. </root>
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Read xml file (advanced)

    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?

  3. #3
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Read xml file (advanced)

    Well what i have now that is working....

    Qt Code:
    1. QFile xmlfile("/home/development/ttm/moives/xml/strings.xml");
    2. if (xmlfile.open(QIODevice::ReadOnly)) {
    3. QXmlStreamReader xml(&xmlfile);
    4. while (!xml.atEnd()) {
    5. xml.readNext();
    6. if (xml.isStartElement() && xml.name() == "movie") {
    7. ui->debugMovie->setText(xml.readElementText());
    8.  
    9. }
    10. }
    11.  
    12. }else {
    13. ui->debugMovie->setText("Not Reading xmlFile");
    14. }
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. QString movFiledb = ui->debugMovie->text();
    To copy to clipboard, switch view to plain text mode 

    then to set the phonon movie and stuff

    Qt Code:
    1. QString vidpath = QApplication::applicationDirPath();
    2. vidpath = "/home/development/ttm/moives/";
    3. obj_mediaobject->enqueue(Phonon::MediaSource(vidpath + movFiledb));
    To copy to clipboard, switch view to plain text mode 

    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 ?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,315
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Read xml file (advanced)

    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.

  5. #5
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Read xml file (advanced)

    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

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,315
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Read xml file (advanced)

    Try this link: http://twolinux.blogspot.com/2010/10...yer-in-qt.html

    I don't have an example myself.

  7. #7
    Join Date
    Oct 2011
    Location
    Toronto Canada
    Posts
    97
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Read xml file (advanced)

    thanks ill try that.. i will also look into qstringlist

Similar Threads

  1. Read contents from the file using QHTTP Read()?
    By Gokulnathvc in forum Newbie
    Replies: 2
    Last Post: 21st June 2011, 08:03
  2. Read the file into
    By offline in forum Qt Programming
    Replies: 7
    Last Post: 12th April 2010, 12:11
  3. is qt phonon can read realmedia file and divx file
    By fayssalqt in forum Qt Programming
    Replies: 1
    Last Post: 27th January 2009, 15:42
  4. Replies: 1
    Last Post: 20th June 2008, 18:43
  5. Read An Xml File
    By Alienxs in forum Qt Programming
    Replies: 3
    Last Post: 5th January 2007, 00:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.