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. unable to delete file using dir->remove() function
Forum Updated to NodeBB v4.3 + New Features

unable to delete file using dir->remove() function

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 2.8k Views 2 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
    vicky07
    wrote on last edited by
    #1

    In the following code filenames and directories are stored in QListWidget (as shown in image)
    I'm unable to delete the file
    (Basically an attempt to delete file present in more than one folder.)

    0_1508788055726_QTforum.png

    for(int row=0; row< ui->listWidget_dirList->count(); row++)
        {
            QListWidgetItem *item= ui->listWidget_dirList->item(row);
            if(item->checkState()==2)
            {
                qDebug()<< item->text();
                dir= new QDir(item->text());
                qDebug()<< dir->remove(filename);  //shows 'false' on console
            }
            else
            {
                filename= item->text();
            }
        }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From the looks of it, you are trying to build a QDir with a file path which seem strange. Wouldn't QFile::remove be a better fit in your applicaation ?

      On a side note, you are leaking QDir objects. You always create a new QDir and do not delete it. From the looks of it, a local stack object should be enough (but again, consider first QFile9

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

      V 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        From the looks of it, you are trying to build a QDir with a file path which seem strange. Wouldn't QFile::remove be a better fit in your applicaation ?

        On a side note, you are leaking QDir objects. You always create a new QDir and do not delete it. From the looks of it, a local stack object should be enough (but again, consider first QFile9

        V Offline
        V Offline
        vicky07
        wrote on last edited by
        #3

        @SGaist
        how can I use QFile::remove() as, its argument demands the filename, but I don't want the file to be removed from all directories. I'm leaving it for user to select those locations from which they want to remove. and thank you for your side note.

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

          From the looks of it, you are providing the user with a list of file paths, are you not ?

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

          V 1 Reply Last reply
          0
          • SGaistS SGaist

            From the looks of it, you are providing the user with a list of file paths, are you not ?

            V Offline
            V Offline
            vicky07
            wrote on last edited by
            #5

            @SGaist
            yes

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

              Then you already have the full paths to each file your users would like to delete hence my proposition of using QFile.

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

              V 1 Reply Last reply
              3
              • SGaistS SGaist

                Then you already have the full paths to each file your users would like to delete hence my proposition of using QFile.

                V Offline
                V Offline
                vicky07
                wrote on last edited by
                #7

                @SGaist
                it solved my problem
                thanks a ton:))))

                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