I am trying to copy a file from one directory to another

Tried QFile::copy(). The file is copied but the size is zero Kb

Tried placing a dummy file and then replacing with original

But still the size is 0 Kb.

Qt Code:
  1. QDir qd;
  2. QFile srcfile;
  3. QFile destifile;
  4.  
  5. QString dbsrcfilepath = qd.currentPath().append("/learnOn1.sqlite");
  6. dbsrcfilepath = QDir::toNativeSeparators(dbsrcfilepath);
  7. // dbsrcfilepath : "/Users/user/build-learnOn-Desktop_Qt_5_4_0_clang_64bit-Debug/learnOn.app/Contents/MacOS/learnOn1.sqlite"
  8. QString libpath = qd.homePath() + QDir::separator()+"learnOnContent" + QDir::separator();
  9. if(!(QDir(libpath).exists()))
  10. QDir().mkdir(libpath);
  11. QString dbdestinationfilepath = libpath.append("learnOn.sqlite");
  12. //dbdestinationfilepath : "/Users/user/learnOnContent/learnOn.sqlite"
  13.  
  14. dbdestinationfilepath = QDir::toNativeSeparators(dbdestinationfilepath);
  15.  
  16. srcfile.setFileName(dbdestinationfilepath);
  17. destifile.setFileName(dbsrcfilepath);
  18. if(!srcfile.exists())
  19. {
  20. bool success = true;
  21. success &= destifile.open( QFile::ReadOnly );
  22. success &= srcfile.open( QFile::WriteOnly | QFile::Truncate );
  23. qDebug()<<destifile.readAll().length();
  24. success &= srcfile.write( destifile.readAll() ) >= 0;
  25. destifile.close();
  26. srcfile.close();
  27. }
  28. else
  29. {
  30. srcfile.copy(dbdestinationfilepath);
  31. }
To copy to clipboard, switch view to plain text mode 

The copy is not proper. File size is always 0.

Kindly help to resolve this issue.

Thanks in advance