Results 1 to 3 of 3

Thread: QT and XML

  1. #1
    Join Date
    Feb 2012
    Posts
    33
    Qt products
    Qt4

    Default QT and XML

    I want to read the contents of a XML file. This in my code:


    QDomDocument doc("mydocument");
    QFile file("CHOIX_DE_LA_CATEGORIE.xml");

    if (!file.open(QIODevice::ReadOnly))
    return;

    if (!doc.setContent(&file))
    {
    file.close();
    return;
    }

    file.close();

    QDomElement docElem = doc.documentElement();

    QDomNode n = docElem.firstChildElement("ss:Worksheet");

    if (!n.isNull() && n.isElement())
    {
    QDomElement e = n.toElement();
    ui->listWidget->addItem(e.text());
    }


    When I execute the program, in then listWidget is added a single line with all the contents of my file!! All the file in a single line without space.

    Why???

    How can I read from the file the single elements, the single fields?

  2. #2
    Join Date
    Feb 2011
    Posts
    354
    Thanks
    17
    Thanked 27 Times in 24 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: QT and XML

    try
    Qt Code:
    1. e.nodeName()
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QT and XML

    What is the structure of the file?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.