Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt fails to create xml file: "No such file or directory"



  • I use code from tutorial and I get this error. I use Windows 10 and Qt Creator 4.7.1. I try to create Qt Widget application. Please help! I am stuck =(

    QDomDocument document;
    // Making the root element
    QDomElement root = document.createElement("Dorms");
    
    // Adding the root element to the docuemnt
    document.appendChild(root);
    QFile file;
    file.setFileName("C:/logs.xml");
    QFile("C:/logs.xml").setPermissions(QFileDevice::WriteOwner);
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
    {
        qDebug() << "Failed to open";
        qDebug() << file.errorString();
    }
    else
    {
        QTextStream stream(&file);
        stream << document.toString();
        file.close();
        qDebug() << "Done";
    }

  • Moderators

    The "C" drive access is restricted on modern Windowses. Try another path.

    Also, this line is completely unnecessary:

    QFile("C:/logs.xml").setPermissions(QFileDevice::WriteOwner);
    


  • I found out that on Windows I need to use this kind of slash "\", so error is gone, it tells that file is created but directory is empty.


  • Lifetime Qt Champion

    @Katia said in Qt fails to create xml file: "No such file or directory":

    I found out that on Windows I need to use this kind of slash "\"

    Speaking for Qt, that is wrong.

    @sierdzio is right, check permissions.



  • @aha_1980 , I am sorry but how do I check permissions? I tried different directories and everywhere it failed. Also the guy who told me to use backslash told that he checked and it worked for him perfectly.

    I added to program checking if file exists. Qt tells it does but directory is empty.


  • Lifetime Qt Champion

    Hi,

    What do you get if you try to open a file that actually exists on your hard drive ?


Log in to reply