Results 1 to 4 of 4

Thread: saveDatabaseAs?

  1. #1
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question saveDatabaseAs?

    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)?

    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.

  2. #2
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: saveDatabaseAs?

    No one has any suggestions?

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: saveDatabaseAs?

    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:
    Qt Code:
    1. QSqlTableModel *curentModel = ...; //the existing model
    2. QSqlTableModel *newModel = new QSqlTableModel();
    3. for(int i = 0; i != currentModel->rowCount(); ++i )
    4. {
    5. QSqlRecord rec = currentModel->record(i);
    6. newModel->insertRecord(-1, rec);
    7. }
    To copy to clipboard, switch view to plain text mode 
    It is possible that I missed some initialization parameters there, but nothing too important I hope .

    Regards.

  4. The following user says thank you to marcel for this useful post:

    grellsworth (6th August 2007)

  5. #4
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: saveDatabaseAs?

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.