Results 1 to 5 of 5

Thread: Synchronize a config file handled QSettings on SMB

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Synchronize a config file handled QSettings on SMB

    Hello everyone,

    We used QSettings to handle the config file of our program. Works great, but now the config file should lie on a smb share with multiple clients accessing it. This crashes, because the locking of QSettings doesn't seem to work and sometimes the config file is messed up.

    We already found QSettingsl#registerFormat an tought about writing a own function, that creates a lock(file) and than uses the orignal write function to write the file, but that does not work, because we can't access the orignal write function. Locking from outside QSettings seems not to work either, because its not predictable when the QSettings is saved.

    Has anyone a good idea how to get around this problem?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Synchronize a config file handled QSettings on SMB

    maybe something like:
    1. A client that wants to write checks the existence of a lock file.
    2. If lock file does not exist create one.
    3. If a lock file exists, do 1. periodically.
    4. Write settings.
    5. Delete lock file.

    EDIT:
    A lock file in the context above is just an empty file in a known location.
    You don't need to re write anything for that.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Synchronize a config file handled QSettings on SMB

    We already thought about this mechanism, but that is not our main problem. Our main problem is, that its not predicable when QSettings wants to write, but after looking into the sources we found out, that is responds to a QEvent::UpdateRequest
    Qt Code:
    1. bool QSettings::event(QEvent *event)
    2. {
    3. Q_D(QSettings);
    4. if (event->type() == QEvent::UpdateRequest) {
    5. d->update();
    6. return true;
    7. }
    8. return QObject::event(event);
    9. }
    10.  
    11. void QSettingsPrivate::update()
    12. {
    13. flush();
    14. pendingChanges = false;
    15. }
    16.  
    17.  
    18. void QConfFileSettingsPrivate::flush()
    19. {
    20. sync();
    21. }
    To copy to clipboard, switch view to plain text mode 

    sync is only called in the constructor/destructor and on request. So we think, that there is a good chance to get around this issue by using QObject#eventFilter and saving on our just before the destructor is called. (constructor is uncritical since it just reads the file)

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Synchronize a config file handled QSettings on SMB

    Why don't you subclass QSettings? In the constructor you enable the lock (create the lock-file), and in the destructor you disable the lock.

    Then you use only local instances of your subclass - as the troll suggest for QSettings.

    HIH

    Johannes

  5. #5
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Synchronize a config file handled QSettings on SMB

    That sounds to me like the best solution. But since in our current implementation we hold the QSettings we implemented it with the event filter. We're currently testing it, but it seems to work. But for the next release we're considering to use the local instances approach.

Similar Threads

  1. How to use QSettings to read INI file
    By Cantora in forum Newbie
    Replies: 8
    Last Post: 16th June 2011, 08:14
  2. QSettings, my own format of config-file
    By IPFreely in forum Qt Programming
    Replies: 2
    Last Post: 14th November 2007, 20:07
  3. Using QSettings to read pre-made INI file..
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 3rd May 2007, 05:36
  4. config file class
    By feizhou in forum Qt Programming
    Replies: 2
    Last Post: 23rd November 2006, 07:49
  5. Config file parsing
    By Vash5556 in forum Qt Programming
    Replies: 2
    Last Post: 10th September 2006, 23:11

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.