Results 1 to 4 of 4

Thread: Backing up a file.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Backing up a file.

    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.

    Qt Code:
    1. QString filter = tr("Database Backup (*.dbb)");
    2. QString fileName = QFileDialog::getSaveFileName(this,tr("Backup Database"),QDir::homePath(),filter);
    3.  
    4. if(!fileName.isEmpty()){
    5. QString filePath = QDir::homePath();
    6. filePath.append("/database");
    7. QFile sourceFile(filePath);
    8. if(!sourceFile.open(QIODevice::ReadOnly)){
    9. //Error Message
    10. return;
    11. }
    12. QFile destFile(fileName);
    13. if(!destFile.open(QIODevice::WriteOnly)){
    14. //Error Message
    15. return;
    16. }
    17. QTextStream sourceStream(&sourceFile);
    18. QTextStream destStream(&destFile);
    19. QByteArray data;
    20. sourceStream>>data;
    21. data = qCompress(data);
    22. destStream<<data;
    23. sourceFile.close();
    24. destFile.close();
    25. }
    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.
    Last edited by munna; 30th September 2006 at 10:51. Reason: Spelling mistake

Similar Threads

  1. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 11:47
  2. Qt 3.3.4 -> Qt 4.1.2, moc file issue
    By philski in forum Qt Tools
    Replies: 1
    Last Post: 11th September 2006, 21:08
  3. .ui file name and classname
    By Rekha in forum Newbie
    Replies: 3
    Last Post: 12th August 2006, 01:53
  4. SQLite-DB in a qrc file
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2006, 19:24
  5. QHttp GET File & Password
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 11th June 2006, 13:04

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
  •  
Qt is a trademark of The Qt Company.