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.
QString dbsrcfilepath
= qd.
currentPath().
append("/learnOn1.sqlite");
dbsrcfilepath
= QDir::toNativeSeparators(dbsrcfilepath
);
// dbsrcfilepath : "/Users/user/build-learnOn-Desktop_Qt_5_4_0_clang_64bit-Debug/learnOn.app/Contents/MacOS/learnOn1.sqlite"
QString libpath
= qd.
homePath() + QDir::separator()+"learnOnContent" + QDir::separator();
if(!(QDir(libpath
).
exists())) QString dbdestinationfilepath
= libpath.
append("learnOn.sqlite");
//dbdestinationfilepath : "/Users/user/learnOnContent/learnOn.sqlite"
dbdestinationfilepath
= QDir::toNativeSeparators(dbdestinationfilepath
);
srcfile.setFileName(dbdestinationfilepath);
destifile.setFileName(dbsrcfilepath);
if(!srcfile.exists())
{
bool success = true;
success
&= destifile.
open( QFile::ReadOnly );
success
&= srcfile.
open( QFile::WriteOnly |
QFile::Truncate );
qDebug()<<destifile.readAll().length();
success &= srcfile.write( destifile.readAll() ) >= 0;
destifile.close();
srcfile.close();
}
else
{
srcfile.copy(dbdestinationfilepath);
}
QDir qd;
QFile srcfile;
QFile destifile;
QString dbsrcfilepath = qd.currentPath().append("/learnOn1.sqlite");
dbsrcfilepath = QDir::toNativeSeparators(dbsrcfilepath);
// dbsrcfilepath : "/Users/user/build-learnOn-Desktop_Qt_5_4_0_clang_64bit-Debug/learnOn.app/Contents/MacOS/learnOn1.sqlite"
QString libpath = qd.homePath() + QDir::separator()+"learnOnContent" + QDir::separator();
if(!(QDir(libpath).exists()))
QDir().mkdir(libpath);
QString dbdestinationfilepath = libpath.append("learnOn.sqlite");
//dbdestinationfilepath : "/Users/user/learnOnContent/learnOn.sqlite"
dbdestinationfilepath = QDir::toNativeSeparators(dbdestinationfilepath);
srcfile.setFileName(dbdestinationfilepath);
destifile.setFileName(dbsrcfilepath);
if(!srcfile.exists())
{
bool success = true;
success &= destifile.open( QFile::ReadOnly );
success &= srcfile.open( QFile::WriteOnly | QFile::Truncate );
qDebug()<<destifile.readAll().length();
success &= srcfile.write( destifile.readAll() ) >= 0;
destifile.close();
srcfile.close();
}
else
{
srcfile.copy(dbdestinationfilepath);
}
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
Bookmarks