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. Copy File from One folder to other Folder.New to Qt
Forum Updated to NodeBB v4.3 + New Features

Copy File from One folder to other Folder.New to Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 4.4k 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.
  • J Offline
    J Offline
    Jimit Rupani
    wrote on last edited by
    #1

    files.h

    #ifndef FILES_H
    #define FILES_H
    
    #include <QObject>
    
    class files
    {
    public:
        files();
        QString srcPath = "/home/roopkumar/FileTransfer/1.txt";
        QString dstPath = "/media/roopkumar/Downloads";
        bool copyfile();
    };
    
    #endif // FILES_H
    
    
    include "files.h"
    #include<QFile>
    
    files::files()
    {
    
    }
    
     bool files::copyfile(){
         if (QFile::exists(dstPath))
         {
             QFile::remove("home/roopkumar/Downloads/.txt");
         }
    
        QFile sourceFile( srcPath);
        QFile destFile( dstPath );
        bool success = true;
        success &= sourceFile.open( QFile::ReadOnly );
        success &= destFile.open( QFile::WriteOnly | QFile::Truncate );
        success &= destFile.write( sourceFile.readAll() ) >= 0;
         QFile::copy(srcPath,dstPath);
        sourceFile.close();
        destFile.close();
    
        return success;
    }
    **files.cpp**
    

    main.cpp

     files *f = new files();
        f->copyfile();
    

    Error : QIODevice::write (QFile, "/media/roopkumar/Downloads/2.txt"): device not open
    where am i doing mistake help me with that.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      dstPath is a folder, not a file.
      You don't need to open and read/write them QFile::copy is enough. all you need is:

      QString dstPath = "/media/roopkumar/Downloads/2.txt"
      if(QFile::exists(dstPath))
      QFile::remove(dstPath);
      Q_ASSUME(QFile::copy("/home/roopkumar/FileTransfer/1.txt",dstPath ));
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      5

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved