unexpected end of file with QDomDocument

  • Hi every one,

    I've got a problem with QDomDocument.

    When I use the method setContent with an xml file I get the error "unexpected end of file line 1 column 1"

    This is a part of my source code

    int xmlDom::parseXmlWeapon(QString nomArme, st_Arme *armeOut)
        m_domDocument = new QDomDocument("Weapon");
        m_xmlFileName = nomArme.append(".xml");
            return -1;
        QByteArray text = m_xmlFile->readAll();
        int errorLine, errorColumn;
        QString ErrorMessage;
        if(!m_domDocument->setContent(m_xmlFile, true, &ErrorMessage, &errorLine,&errorColumn))
            return -1;

    and this is my xml file that I want to extract information.

    <?xml version="1.0" encoding="UTF-8"?>
       <special>Deux main</special>

  • I already read some other forum but it does not bring the right solution.

    I work on QtCretor on Windows 10 with mingw

    Thank you very much

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    With QByteArray text = m_xmlFile->readAll();, you're reading the file completely. Then right after that you call m_domDocument->setContent on the same file, which current position will be at the end of the file. So either use the content fo your textvariable to put into m_domDocument or reset the position of the file before using it to load m_domDocument.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.