Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt fails to create xml file: "No such file or directory"

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

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
6 Posts 4 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Katia
    wrote on last edited by
    #1

    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";
    }
    
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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);
      

      (Z(:^

      1 Reply Last reply
      2
      • K Offline
        K Offline
        Katia
        wrote on last edited by Katia
        #3

        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.

        aha_1980A 1 Reply Last reply
        0
        • K Katia

          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.

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          Qt has to stay free or it will die.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Katia
            wrote on last edited by Katia
            #5

            @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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved