tags:

views:

32

answers:

2

I have a pretty standard Qt GUI application. It uses Qt's QSettings to store a number of settings, and it all works fine.

However, when multiple copies of the application are launched, and settings are changed in one or the other, the different copies can appear inconsistent (as one has the "old" copy of the data).

What are the preferred solutions to this problem? I guess this problem occurs, even outside of the Qt arena.

A: 

I always consider having multiple applications running on the same dataset, with a high probability of collision, a bit hairy.

Maybe it would be better for you to just forbid multiple instances, and use QtSingleApplication, to be found in the Qt Solutions repository (along with other nice widgets).

phresnel
+1  A: 

The QSettings docs mention this in the Accessing Settings from Multiple Threads or Processes Simultaneously section:

  • QSettings can safely be used from different processes (which can be different instances of your application running at the same time or different applications altogether) to read and write to the same system locations. It uses advisory file locking and a smart merging algorithm to ensure data integrity. Changes performed by another process aren't visible in the current process until sync() is called.

Have you tried to call yoursettings.sync() from the writer app after writing values and from the reader app before reading them? If so, and if your logic is correct, this sounds like a Qt bug.

Mihai Limbășan