Hi,
Thanks for the replies, I have the following code working well,
void Loader::saveToFile()
{
QString fileName
= QFileDialog::getSaveFileName( this, tr
("Save File As..."),
QDir::homePath(), tr
("txt (*.txt)"));
if (fileName.isEmpty())
return;
else
{
{
QMessageBox::information(this, tr
("Unable to open file"),
file.
errorString());
return;
}
// Need to find a way to clear all present data in file, if the file already exists.
out << channels; // "channels" is a QMap<QString, QString> which has the relevant information already inserted.
}
}
void Loader::saveToFile()
{
QString fileName = QFileDialog::getSaveFileName( this, tr("Save File As..."), QDir::homePath(), tr("txt (*.txt)"));
if (fileName.isEmpty())
return;
else
{
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly))
{
QMessageBox::information(this, tr("Unable to open file"), file.errorString());
return;
}
// Need to find a way to clear all present data in file, if the file already exists.
QDataStream out(&file);
out.setVersion(QDataStream::Qt_4_3);
out << channels; // "channels" is a QMap<QString, QString> which has the relevant information already inserted.
}
}
To copy to clipboard, switch view to plain text mode
The problem I now have is that if I open a file that already exists, I overwrite my data to this file, but any original data that is not overwritten still remains... what I need is a way to delete all original data in the file before I write my new data.
Is there a simple way to delete all data in a file?
Thanks
Bookmarks