Results 1 to 4 of 4

Thread: QSettings write and read function

  1. #1
    Join Date
    Jul 2008
    Location
    Norway, Trondheim
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QSettings write and read function

    When using ini files, does anyone know how QSettings transforms say a QStringList (or any other object) into the text that is written to the ini file? I am trying to encrypt the data before it is written. It would be great to just access the default read and write functions of qsettings, but I don`t find any info on these functions... Another possibility could be to tell QSettings to read/write using the standard functions to a QBuffer, then encrypt and then write to file. Doesn anyone know how to do this?

    -Ivar

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings write and read function

    Quote Originally Posted by ivareske View Post
    When using ini files, does anyone know how QSettings transforms say a QStringList (or any other object) into the text that is written to the ini file?
    Qt is open-source. The easiest way is to look at the code responsible for this.

    But since you want to do mangle the data I don't see the point in duplicating what QSettings does for ini files. Just provide your own read and write functions that save to a custom format and do the encryption as part of the process. The simplest possible read/write combination is:
    Qt Code:
    1. bool readFile(QIODevice &device, QSettings::SettingsMap &map) {
    2. QDataStream stream(&device);
    3. device >> map;
    4. return true;
    5. }
    6.  
    7. bool writeFile(QIODevice &device, const QSettings::SettingsMap &map) {
    8. QDataStream stream(&device);
    9. device << map;
    10. return true;
    11. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2008
    Location
    Norway, Trondheim
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSettings write and read function

    Ok, but I still don`t understand how to convert my custom classes to QString. The map contains my custom object as a QVariant, how to I convert that to string so I can encrypt it?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSettings write and read function

    I don't see your point. You can encrypt data regardless of the format it is in.
    Qt Code:
    1. bool writeFile(QIODevice &device, const QSettings::SettingsMap &map) {
    2. QBuffer buffer;
    3. buffer.open(QIODevice::WriteOnly);
    4. QDataStream stream(&buffer);
    5. device << map;
    6. QByteArray encrypted = encrypt(buffer.data());
    7. device.write(encrypted);
    8. return true;
    9. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 14th January 2011, 11:57
  2. Replies: 6
    Last Post: 7th December 2010, 12:32
  3. Replies: 2
    Last Post: 2nd November 2010, 05:15
  4. QSettings , read only avaiable?
    By patrik08 in forum Qt Programming
    Replies: 5
    Last Post: 18th November 2007, 15:21
  5. Replies: 4
    Last Post: 1st February 2006, 17:17

Tags for this Thread

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.