Copy file even when destination exists (in Qt)

Copy file even when destination exists (in Qt)

Asked on January 10, 2019 in Qt.
Add Comment


  • 3 Answer(s)

    Copy the  file  when destination is exists:

    if (QFile::exists("/home/user/dst.txt"))
    {
        QFile::remove("/home/user/dst.txt");
    }
     
    QFile::copy("/home/user/src.txt", "/home/user/dst.txt");
    
    Answered on January 10, 2019.
    Add Comment

    The following given code is:

    Just call remove() before copy();
    
    
    Answered on January 10, 2019.
    Add Comment

    The alternative below code is:

    while !QFile::copy("/home/user/src.txt", "/home/user/dst.txt")
    {
        QFile::remove("/home/user/dst.txt");
    }
    

    It  is not a  original  solution  to event the conditions by blocking  the removes.

    Answered on January 10, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.