Hi,
I have a application that uses Sqlite to store data and also the option to backup this data.
I wrote the following code but is not working.
QString filter
= tr
("Database Backup (*.dbb)");
if(!fileName.isEmpty()){
filePath.append("/database");
QFile sourceFile
(filePath
);
//Error Message
return;
}
QFile destFile
(fileName
);
//Error Message
return;
}
sourceStream>>data;
data = qCompress(data);
destStream<<data;
sourceFile.close();
destFile.close();
}
QString filter = tr("Database Backup (*.dbb)");
QString fileName = QFileDialog::getSaveFileName(this,tr("Backup Database"),QDir::homePath(),filter);
if(!fileName.isEmpty()){
QString filePath = QDir::homePath();
filePath.append("/database");
QFile sourceFile(filePath);
if(!sourceFile.open(QIODevice::ReadOnly)){
//Error Message
return;
}
QFile destFile(fileName);
if(!destFile.open(QIODevice::WriteOnly)){
//Error Message
return;
}
QTextStream sourceStream(&sourceFile);
QTextStream destStream(&destFile);
QByteArray data;
sourceStream>>data;
data = qCompress(data);
destStream<<data;
sourceFile.close();
destFile.close();
}
To copy to clipboard, switch view to plain text mode
The destination file is getting created but it's size is only 10 Bytes.
Can someone please tell me what is wrong with the code ?
Thanks a lot.
Bookmarks