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. How to delete a file within thread using
Forum Updated to NodeBB v4.3 + New Features

How to delete a file within thread using

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 8.3k 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.
  • P Offline
    P Offline
    phamvanan
    wrote on last edited by
    #1

    I try to delete a file, but i get error it's using by other progressing. Specially, I use a thread to copy content file but during copying, i want to crop down copy progressing and delete the file not intact.
    How to disconect that progress to file deleted.

    Thanks

    -PVA-

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      if the file is opened by your application you need to make sure that you call QFile::close() on it.
      If the file is locked by another process/application there is nothing you can/should do.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • P Offline
        P Offline
        phamvanan
        wrote on last edited by
        #3

        I try to use:
        @QFile("C:/abc.mp3").close();
        QFile("C:/abc.mp3").remove();@
        but not working.
        Get a error:
        @error: C2352: 'QFile::close' : illegal call of non-static member function@

        -PVA-

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          i don't believe that this is the actual code you are using!
          Why don't you post the correct code when you expect us to help you?!

          I assume you call a member of type QFile out of a static method, right?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • P Offline
            P Offline
            phamvanan
            wrote on last edited by
            #5

            I'm really sorry you,
            I get error above when i use:
            @QFile::close();@
            in my class. So, I try other away,
            @ QFile("C:/abc.mp3").close();
            QFile("C:/abc.mp3").remove();
            @
            But also file not deleted.

            -PVA-

            1 Reply Last reply
            0
            • P Offline
              P Offline
              phamvanan
              wrote on last edited by
              #6

              That right,
              @void MainWindow::on_pushButton_clicked()
              {
              QFile::close();
              QFile("c:/des/1 (1).iso").close();
              this->destination->remove("c:/des/1 (1).iso");
              }@

              destination is variable QDir type

              -PVA-

              1 Reply Last reply
              0
              • raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                QFile::close() is not a static function so remove this line and use it like in line 4.
                @
                QFile file("c:/des/1 (1).iso");
                file.close();
                qDebug() << "QFile::remove()" << file.remove();
                qDebug() << "QFile::errorString()" << file.errorString();
                @
                What are the outputs of this code?

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  phamvanan
                  wrote on last edited by
                  #8

                  Hi, outputs as below:
                  @QFile::remove() false
                  QFile::errorString() "The process cannot access the file because it is being used by another process.@

                  -PVA-

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    you can use "ProcessExplorer":http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx and check which process is holding the handle to that file.
                    If it's your application check your code again where you "open":http://qt-project.org/doc/qt-4.8/qfile.html#open it and make sure you close it properly. If it's another application there is nothing you can do...

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      phamvanan
                      wrote on last edited by
                      #10

                      Thank you very much,
                      I understand you said.
                      Let me see again.
                      By the way, Have you a simple example about postEvent() function to me clear it?
                      An.

                      -PVA-

                      1 Reply Last reply
                      0
                      • raven-worxR Offline
                        raven-worxR Offline
                        raven-worx
                        Moderators
                        wrote on last edited by
                        #11

                        [quote author="phamvanan" date="1371204058"]
                        By the way, Have you a simple example about postEvent() function to me clear it?[/quote]
                        "Here":http://doc.qt.digia.com/qq/qq11-events.html#syntheticevents you go.

                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                        If you have a question please use the forum so others can benefit from the solution in the future

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          phamvanan
                          wrote on last edited by
                          #12

                          I have a problem. I have a two objects, one is Copier object and else MainWindow Object,
                          I want create postEvent at Copier class to MainWindow class.
                          How to do that? At MainWindow how to get that event.
                          Addition, How to send a data with postEvent function?
                          Thanks.

                          -PVA-

                          1 Reply Last reply
                          0
                          • raven-worxR Offline
                            raven-worxR Offline
                            raven-worx
                            Moderators
                            wrote on last edited by
                            #13

                            open the link i've posted before and just scroll down a little bit.... :/

                            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                            If you have a question please use the forum so others can benefit from the solution in the future

                            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