munna
30th September 2006, 10:49
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)");
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();
}
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.
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)");
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();
}
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.