ejoshva
10th April 2015, 11:37
I am copying a certail file from one path to another using the below code
QString curdir = QCoreApplication::applicationDirPath().append("/db_ssparkl.sqlite");
profileName= qd.homePath().append("/ssparkl.sqlite");
QFile dbfile;
QFile destifile;
destifile.setFileName(profileName);
dbfile.setFileName(curdir);
if(dbfile.exists() && !destifile.exists())
{
bool success = true;
success &= dbfile.open( QFile::ReadOnly );
success &= destifile.open( QFile::WriteOnly | QFile::Truncate );
success &= destifile.write( dbfile.readAll(),dbfile.size()) >= 0;
destifile.close();
dbfile.close();
}
I am writing by reading the source file content onto destination file content, since QFile::copy didn't work as expected as the file copied show size as zero bytes.
Now the file is getting copied fully as expected. But it's being treated text document and not as exec(app)
How to make it treated as app.
Added after 9 minutes:
I googled it and found that, after writing the file has to be given +x option.
chmod +x filename
how do I do this in QT
Added after 16 minutes:
Got it solved as below
QString changeToExec = "chmod +x "+destifile.fileName();
QProcess::execute(changeToExec);
QString curdir = QCoreApplication::applicationDirPath().append("/db_ssparkl.sqlite");
profileName= qd.homePath().append("/ssparkl.sqlite");
QFile dbfile;
QFile destifile;
destifile.setFileName(profileName);
dbfile.setFileName(curdir);
if(dbfile.exists() && !destifile.exists())
{
bool success = true;
success &= dbfile.open( QFile::ReadOnly );
success &= destifile.open( QFile::WriteOnly | QFile::Truncate );
success &= destifile.write( dbfile.readAll(),dbfile.size()) >= 0;
destifile.close();
dbfile.close();
}
I am writing by reading the source file content onto destination file content, since QFile::copy didn't work as expected as the file copied show size as zero bytes.
Now the file is getting copied fully as expected. But it's being treated text document and not as exec(app)
How to make it treated as app.
Added after 9 minutes:
I googled it and found that, after writing the file has to be given +x option.
chmod +x filename
how do I do this in QT
Added after 16 minutes:
Got it solved as below
QString changeToExec = "chmod +x "+destifile.fileName();
QProcess::execute(changeToExec);