PDA

View Full Version : saveDatabaseAs?



grellsworth
2nd August 2007, 16:39
I want to make a menu option that takes the currently selected database and saves it (with any chages that have been made) to a different file. I don't want the changes to be saved to the original database.

I'm using a QTableView to show the contents of the database.

Is there an easy way to make a copy of the QSqlTableModel, including the data that has been changed, but not submitted to the database yet (without actually saving the data first)? :confused:

I could just use QFile::copy() to copy the database file to the new name, but I'd lose any changes that were made. If I submit the changes to the database first, then copy it, it kind of invalidates the idea of a "Save As" (your original file changes also).

I'm using Qt 4.2/4.3

Sincerely,

Gordon E.

grellsworth
6th August 2007, 16:59
No one has any suggestions?

marcel
6th August 2007, 17:12
I don't know if it will work, but can't you copy the current query results(or table) to another table model?
Something like:


QSqlTableModel *curentModel = ...; //the existing model
QSqlTableModel *newModel = new QSqlTableModel();
for(int i = 0; i != currentModel->rowCount(); ++i )
{
QSqlRecord rec = currentModel->record(i);
newModel->insertRecord(-1, rec);
}

It is possible that I missed some initialization parameters there, but nothing too important I hope :).

Regards.

grellsworth
6th August 2007, 17:41
I was thinking something along those lines, I'll give it a try.
It just seems to be a lot of trouble to go through, but I don't see any easier way, either.

Thank You.