Results 1 to 10 of 10

Thread: Storing the program data in a "safe place"

  1. #1
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Storing the program data in a "safe place"

    Hello.

    In my peer2mail client, I've got a "file" class and the objects of this class, appended to QList named fileList represents files that are currently downloaded. Everything's nice, but on the program startup I would like to load these files' data which were in the program when I closed it lately. So this data should be stored somewhere. It would be nice if the user couldn't modify it (I'm not talking about deletion, because I think it's impossible to prevent them from being removed, hm?). So these are my two questions:
    1) Where should I store these data and what should I use to store them (which Qt classes for example)?
    2) When should I save the data (it includes for example currently downloaded kilobytes of files so it's changing all the time) - create a QTimer and save it every 100 miliseconds? That's also not to accurate...

    Thanks in advance .

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Storing the program data in a "safe place"

    Keep an in-memory database and flush it to disk once a minute or on program quite.

    If you notice an abnormal shutdown, you can take the file, read the downloaded files, compare, and repair the database.

  3. #3
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing the program data in a "safe place"

    I'm not sure if I get it. By in-memory database you mean a set of lines of text, each line containing info about one file? Or something else? When I "flush it in to disk" do I have to do something special, to save it as *.dat file? Sorry for my newbism (oh, nice word), it's the first time I'm storing data like that.

  4. #4
    Join Date
    Jul 2008
    Location
    Norway
    Posts
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Storing the program data in a "safe place"

    Take a look at QDataStream - that's one way of storing your data.
    !sirius

  5. #5
    Join Date
    Apr 2010
    Location
    Rostov-na-Donu, Russia
    Posts
    153
    Thanks
    2
    Thanked 26 Times in 23 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Storing the program data in a "safe place"

    Use QSettings and call it's sync() function to actually save data any time you want ( after each write, ones in a minute, etc. )

  6. #6
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing the program data in a "safe place"

    But should I use QSettings to save such data? AFAIK, QSettings stores the data in the Windows registry (on Windows) - I'm not sure if I should save logins and passwords to mailboxes, or currently downloaded file size there, as plain text. I'd just like to know, how do normal apps store such a data - it can be any download client.

    Sirius - that seems reasonable, I will take a look.

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Storing the program data in a "safe place"

    You don't exactly tell us what "such data" contains. Small configuration items, like password (encrypted), user name, server names, etc. are exactly what QSettings is designed for. For a longer list of files then QSettings is not really suitable (although it could be used). The periodic writing of an in-memory list (QList or Sqlite database) to a physical file is a good option. I would store this sort of information in the locations identified by QDesktopServices::DataLocation or QDesktopServices::CacheLocation (see QDesktopServices::storageLocation()) depending on whether I can easily rebuild the file if it were lost. On Windows these are typically in places not seen by the average user.

  8. #8
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Storing the program data in a "safe place"

    Just to expand a bit: if you're going to be storing sensitive information like passwords, it needs to be stored in an encrypted format of some sort. There's no reason you can't use QSettings to do this, but I don't believe QSettings performs any encryption, so that would require a separate step.

  9. #9
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Storing the program data in a "safe place"

    Quote Originally Posted by ChrisW67 View Post
    The periodic writing of an in-memory list (QList or Sqlite database) to a physical file is a good option.
    Do you mean writing using QDataStream? If I'll use QDataStream, do I still have to care about any encryption of the data (since it's binary data after "serialization")?

    Thanks a lot for what you've told me already.

  10. #10
    Join Date
    Jul 2008
    Location
    Norway
    Posts
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Storing the program data in a "safe place"

    Some ideas:

    Have a class managing username+passwords (with a helper function to encrypt/decrypt the passwords) using QSettings. (This is what QSettings is suited for.)

    Then have another class managing the files being downloaded; provide a nice interface for your app. Internally it may use a QList+QDataStream or QSqlite - whatever suits you best. In this class QSettings is not the best solution IMHO.

    BTW - unencrypted data is unencrypted whether it is stored as binary data or as plain text.
    Last edited by sirius; 5th August 2010 at 10:28.
    !sirius

Similar Threads

  1. Replies: 1
    Last Post: 7th April 2010, 21:46
  2. Replies: 28
    Last Post: 22nd February 2010, 10:27
  3. Replies: 3
    Last Post: 25th August 2009, 13:03
  4. "Cannot run program "C:\Qt\4.3.3\bin\qmake": file not found
    By PeteH in forum Installation and Deployment
    Replies: 1
    Last Post: 7th February 2009, 00:48
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

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.