Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. When I rename a file QFile do not open it

When I rename a file QFile do not open it

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.4k Views 1 Watching
  • 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.
  • V Offline
    V Offline
    valeSimu
    wrote on last edited by
    #1

    Hi,
    in my application I read a file in this way:

    @ QString pathFile = QString::fromWCharArray(p.c_str());

    // Open the XML file
    QFile file(pathFile);
    
    // If we can't open the file
    if (!file.open(QIODevice::ReadOnly)){
        throw MyExceptions(L"Can't open the file " + p);
        return false;
    }
    
    // If we can't set the XML file to the DOM object
    if (!doc.setContent(&file)) {
        file.close();
        throw MyExceptions(L"Can't set the XML file to the DOM object for file " + p);
        return false;
    }
    file.close();
    
    return true;@
    

    it opens any files, but if I rename one of them, rerun the application and open the file I have just renamed, it show this message error:
    Can't open the file bla/bla/bla

    what happen??

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kolegs
      wrote on last edited by
      #2

      can you check what is the result of QFile::exists() method?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ambershark
        wrote on last edited by
        #3

        You might want to make sure pathFile is the renamed file you are expecting. Like kolegs said, also run a file.exists() on it to see if it is even there.

        Renaming the file outside the application shouldn't have any affect on opening it inside the app as long as pathFile points to the correct file.

        My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

        1 Reply Last reply
        0
        • V Offline
          V Offline
          valeSimu
          wrote on last edited by
          #4

          The result is 1 when opening the original file while 0 when I rename it...

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            For both before the rename and after what are the values of pathFile and file.fileName()?

            What is the original name of the file and the renamed name?

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            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