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. QFile::remove works wrong or where is problem?
Forum Updated to NodeBB v4.3 + New Features

QFile::remove works wrong or where is problem?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 3 Posters 4.3k 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.
  • DrageFabeldyrD Offline
    DrageFabeldyrD Offline
    DrageFabeldyr
    wrote on last edited by
    #1

    OS - Android
    I have database file which i can change on PC then copy to my phone.
    Program checks if there is a new one, copy it and then delete.

            bool copySuccess = QFile::copy(new_name, name);
            if (!copySuccess)
            {
                QMessageBox::critical(0, QString("Error!"), "Database wasn't updated", QMessageBox::Ok);
            }
            else
            {
                QMessageBox::critical(0, QString("Yeah!"), "Database was updated", QMessageBox::Ok);
                QFile::remove(new_name);
            }
    

    if i run program again it says there isn't new database file but if i open it's location in file browser i can see it

    why is it so?

    J.HilkJ 1 Reply Last reply
    0
    • DrageFabeldyrD DrageFabeldyr

      OS - Android
      I have database file which i can change on PC then copy to my phone.
      Program checks if there is a new one, copy it and then delete.

              bool copySuccess = QFile::copy(new_name, name);
              if (!copySuccess)
              {
                  QMessageBox::critical(0, QString("Error!"), "Database wasn't updated", QMessageBox::Ok);
              }
              else
              {
                  QMessageBox::critical(0, QString("Yeah!"), "Database was updated", QMessageBox::Ok);
                  QFile::remove(new_name);
              }
      

      if i run program again it says there isn't new database file but if i open it's location in file browser i can see it

      why is it so?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @DrageFabeldyr ,
      you can't overwrite existing files with QFile::copy

      taken from the docu:

      bool QFile::copy(const QString &fileName, const QString &newName)
      This is an overloaded function.
      
      Copies the file fileName to newName. Returns true if successful; otherwise returns false.
      
      If a file with the name newName already exists, copy() returns false (i.e., QFile will not overwrite it).
      
      See also rename().
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      DrageFabeldyrD 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        hi @DrageFabeldyr ,
        you can't overwrite existing files with QFile::copy

        taken from the docu:

        bool QFile::copy(const QString &fileName, const QString &newName)
        This is an overloaded function.
        
        Copies the file fileName to newName. Returns true if successful; otherwise returns false.
        
        If a file with the name newName already exists, copy() returns false (i.e., QFile will not overwrite it).
        
        See also rename().
        
        DrageFabeldyrD Offline
        DrageFabeldyrD Offline
        DrageFabeldyr
        wrote on last edited by
        #3

        @J.Hilk great thanks about copy, now i know what is wrong with it but my question was about remove

        if i remove file program can't see it after that but file browser can

        J.HilkJ 1 Reply Last reply
        0
        • DrageFabeldyrD DrageFabeldyr

          @J.Hilk great thanks about copy, now i know what is wrong with it but my question was about remove

          if i remove file program can't see it after that but file browser can

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @DrageFabeldyr
          mmh, interesting,

          Do you check if the Remove is successful? QFile::remove should return a bool. It won't work for example if the file can't be closed.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          DrageFabeldyrD 1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @DrageFabeldyr
            mmh, interesting,

            Do you check if the Remove is successful? QFile::remove should return a bool. It won't work for example if the file can't be closed.

            DrageFabeldyrD Offline
            DrageFabeldyrD Offline
            DrageFabeldyr
            wrote on last edited by DrageFabeldyr
            #5

            @J-Hilk
            QFile::remove returns true
            then program says there is no file
            file browser shows there is a file
            if i try to copy this file from the phone to pc there is no this file on pc after that so it looks like i'm trying to copy nothing
            if i try to copy file from pc to the phone to the same place it asks me if i want to overwrite the file so it looks like "nothing" really exist

            M 1 Reply Last reply
            0
            • DrageFabeldyrD DrageFabeldyr

              @J-Hilk
              QFile::remove returns true
              then program says there is no file
              file browser shows there is a file
              if i try to copy this file from the phone to pc there is no this file on pc after that so it looks like i'm trying to copy nothing
              if i try to copy file from pc to the phone to the same place it asks me if i want to overwrite the file so it looks like "nothing" really exist

              M Offline
              M Offline
              mvuori
              wrote on last edited by
              #6

              If Qt's functions don't see the file, it doesn't exist. Your file browser "sees" it, but it may be caching the directory - try refreshing it and try to open it into a text editor or something.

              DrageFabeldyrD 1 Reply Last reply
              1
              • M mvuori

                If Qt's functions don't see the file, it doesn't exist. Your file browser "sees" it, but it may be caching the directory - try refreshing it and try to open it into a text editor or something.

                DrageFabeldyrD Offline
                DrageFabeldyrD Offline
                DrageFabeldyr
                wrote on last edited by DrageFabeldyr
                #7

                @mvuori
                i've tried restart my phone, reconnect it to my pc and even connect it to another pc

                and i mean file browser on pc (Windows 7)
                file browser on the phone doesn't see the file (Android)

                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