Results 1 to 3 of 3

Thread: how QXmlStreamReader parse QString

  1. #1
    Join Date
    Aug 2008
    Posts
    11
    Thanks
    1

    Post how QXmlStreamReader parse QString

    hi, all,
    I have a string which is the xml structure. and I want to parse it by QXmlStreamReader,
    but the QXmlStreamReader want the QIODevice as it's parametre, but I only have the string, so How do I convert the string to QIODevice ,is it use the
    QBuffer buff(& myString.toUTF8),
    or QTextStream textStream(&myString) and then textStream.device(),
    both ways seems don't work , any help ,thanks very much!

  2. #2
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: how QXmlStreamReader parse QString

    QXmlStreamReader can accept a string:

    http://doc.qtsoftware.com/4.5/qxmlst...StreamReader-4

    ~codeslicer

  3. #3
    Join Date
    Oct 2009
    Location
    Sweden
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Exclamation Re: how QXmlStreamReader parse QString

    I'm have the same problem here, i have tried using QBuffer,QByteArray and Qstring in different combinations with no succsess

    below is the different ways that i have tried:
    Qt Code:
    1. QSting xml; //with some xml structure
    2.  
    3. QByteArray bArray(xml);
    4. QBuffer buffer;
    5. QBuffer buffer(&bArray)
    6. reader.setDevice(&buffer);
    7.  
    8. //or like this
    9. buffer.setData(xml.toUtf8());
    10.  
    11. //then
    12. buffer.open(QIODevice::ReadOnly)
    13.  
    14. //or this way
    15. reader.addData(xml.toUtf8());
    16.  
    17. //what the heck! this then Grrr
    18. QXmlStreamReader reader(xml);
    To copy to clipboard, switch view to plain text mode 

    after using "setDevice" or just "addData" etc i do the following:

    Qt Code:
    1. int ret = reader.readNext();
    2. while(!reader.atEnd())
    3. {
    4. if(reader.isStartElement())
    5. {
    6. if(reader.name() == "Application")
    7. ReadApplicationElement();
    8. else
    9. reader.raiseError(QObject::tr("Error"));
    10. }
    11. else
    12. reader.readNext();
    13. }
    To copy to clipboard, switch view to plain text mode 

    What am i missing?? it's not the XML because i have tried with QFile and it works that way...

    /Robert

Similar Threads

  1. Qy 4.4.3 MySQL driver failed
    By pamalite in forum Installation and Deployment
    Replies: 2
    Last Post: 23rd January 2010, 01:09
  2. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  3. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  4. qt 4.2.2 install on aix
    By try to remember in forum Installation and Deployment
    Replies: 2
    Last Post: 28th March 2007, 12:19
  5. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.